Published on :
Macro EXTERNE

SAS Macro for Table Version Retrieval (`AHGtabver`)

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
The `AHGtabver` macro is designed to be executed in a distributed SAS© environment, using `rsubmit` to submit code to a remote SAS© server. It takes as input a table identifier number (`ltabno`) and the name of an output macro variable (`outver`).
Inside the `rsubmit` block, a `DATA _NULL_` step is used. It defines a `filename pip pipe` to execute a specific shell command: `cd &root3; tabver &rtabno`. This command navigates to a directory specified by `&root3;` then executes an external program `tabver` with the table number. The output of this external command is captured by the pipe.
The `DATA _NULL_` reads the first line of the pipe's output and uses `call symput` to store this line in a temporary macro variable `rtabver` on the remote server. Finally, `%%sysrput &outver=&rtabver;` is used to return the value of `rtabver` to the local SAS© session, assigning it to the macro variable whose name was passed in the `outver` parameter.
This mechanism allows linking version information from the operating system or a version manager within a SAS© program.
Data Analysis

Type : EXTERNE


The data processed by this macro does not come from traditional SAS datasets (whether SASHELP, internal, or external to the script). It is extracted from the textual output of an external system command (`tabver`) executed via a UNIX pipe. The result is textual information (a version number) stored in a macro variable.

1 Code Block
MACRO DEFINITION
Explanation :
This block defines the `AHGtabver` macro which encapsulates the version retrieval logic. It uses `%syslput` to transfer parameters from the local session to the remote session before `rsubmit`. The code between `rsubmit;` and `endrsubmit;` is executed on the remote server. After the `DATA _NULL_` execution on the remote server, `%%sysrput` returns the value of the `rtabver` macro variable (created on the remote) to the local session, assigning it to the macro variable whose name is provided by `&outver`.
Copied!
1%macro AHGtabver(ltabno,outver);
2 %syslput rtabno=<abno;
3 %syslput outver=&outver;
4 
5rsubmit;
6 
7 DATA _null_;
8 filename pip pipe "cd &root3; tabver &rtabno";
9 INFILE pip;
10 LENGTH line $100;
11 INPUT line;
12 call symput('rtabver',line);
13 RUN;
14 %nrstr(%%)sysrput &outver=&rtabver;
15endrsubmit;
16 
17%mend;
2 Code Block
DATA STEP
Explanation :
This `DATA _NULL_` is executed on the remote server (inside the `rsubmit` block). It does not create a permanent dataset. It is used to:
1. Define a `filename` called `pip` as a pipe (`pipe`) that will execute the shell command `cd &root3; tabver &rtabno`.
2. Use `infile pip` to read the output of this external command.
3. Read the first line of the output into the `line` variable.
4. Use `call symput('rtabver',line);` to create a macro variable named `rtabver` (on the remote server) and assign it the content of `line`. This macro variable will contain the version number returned by the `tabver` system command.
Copied!
1 DATA _null_;
2 filename pip pipe "cd &root3; tabver &rtabno";
3 INFILE pip;
4 LENGTH line $100;
5 INPUT line;
6 call symput('rtabver',line);
7 RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : En-têtes RCS détectés: $Source: /Volumes/app/cdars/prod/prjA258/phase3b4/A2581172/saseng/pds1_0/program/RCS/fmd_site_chg.sasdrvr,v $, $Revision: 1.14 $, $Author: Hui Liu $, $Locker: $, $State: Exp $