Wednesday, March 29, 2017

CALL SET routine

I have dig the CALL SET routine and found two interesting points:
#1. In macro, it will resolve macro variable automatically. It means no leading ampersand is needed.
#2. In macro, it will link the dataset variable to closest macro variable that has same name. If the macro variable does not exist, it will create local one.

1    %macro setvar;
2        %local sex;
3       %let dsid=%sysfunc(open(sashelp.class, i));
4       %syscall set(dsid); /* No leading ampersand with %SYSCALL */
5
6       %put Note: Before fetchobs;
7       %put _local_;
8
9       %let rc=%sysfunc(fetchobs(&dsid, 10));
10      %let rc=%sysfunc(close(&dsid));
11
12      %put Note: After fetchobs, which will create local macro variable which does not exist.;
13      %put _local_;
14   %mend setvar;
15
16   %global name;
17   %setvar

Note: Before fetchobs
SETVAR DSID 1
SETVAR SEX

Note: After fetchobs, which will create local macro variable which does not exist.
SETVAR AGE 12
SETVAR DSID 1
SETVAR HEIGHT 59
SETVAR SEX M
SETVAR WEIGHT 99.5

18
19   %put _global_;
GLOBAL NAME John
GLOBAL RC 0

No comments: