Thursday, April 30, 2009

CALL SYMPUT and CALL SYMPUTX

CALL SYMPUT will convert data step variable value into marco variable value and it will store value of in nearest non-missing symbol table. In case below nearest non-missing symbol table is local symbol table of marco name. When we try to access name macro variable outside the macro SAS issues a warning.

%macro name(string=);
data _null_;
 name = "&string";
 call symput("name",name);
run;
%put &name;
%mend;
%name (string= Vikas);
%put &name;
/*WARNING: Apparent symbolic reference NAME not resolved.*/
CALL SYMPUTX new in SAS v9 can have an extra third argument where you can specify which symbol table you want SAS to store value of this macro variable. Code below is same as above except we are using call symputx and third argument saying we want macro variable to be saved in global symbol table. So this time around we don't get the Warning message.

%macro name(string=);
data _null_;
 name = "&string";
 call symputx("name",name,'G');
run;
%put &name;
%mend;
%name (string= Vikas);
%put &name;

No comments:

Post a Comment