Hello,
How to retrieve the macro variable value for each observation (or particular observation) using %SYSCALL SET() as compared to CALL SYMPUTX() where we can get macro variable value for specific observations (such as 1 anf 19 in exmaple below).
%let dsid=%sysfunc(open(sashelp.class,i));
%syscall set(dsid);
%let rc=%sysfunc(fetchobs(&dsid,1));
%let rc=%sysfunc(close(&dsid));
%put _user_;
%put name = &name age = &age sex = &sex;
data _null_;
set sashelp.class;
call symputx("macvar_name"||put(_n_,best. -l), name);
call symputx("macvar_age"||put(_n_,best. -l), age);
call symputx("macvar_sex"||put(_n_,best. -l), sex);
run;
%put name = &macvar_name1 age = &macvar_age1 sex = &macvar_sex1;
%put name = &macvar_name19 age = &macvar_age19 sex = &macvar_sex19;
Why? Macro is not a replacement for Base SAS. Base SAS holds the data and the data maniplation tools. Macro is only present to generate some code. There is no use in putting all your data into macro variables?
I'm not quite sure what you mean or intend by:
"How to retrieve the macro variable value for each observation (or particular observation)"
most approaches I've seen people attempt with macro values per observation seem to be along the lines of forcing the macro language to do what a data step or other procedure should do. Code dependent on values of varaibles in data set is usually much more amenable to call execute than going through the headache of creating umpteen thousand macro variables and the headaches of keeping all of them straight.
And %syscall, even with set, is very unlikely to have anything to do with "observation", or at least I'm not making your connection. You might provide more on what you are attempting to accomplish if you had the answer to question.
If you use %SYSCALL SET() it populates macros variables that have same names as the dataset variable names. So if your dataset has a variable name AGE then when you fetch an observation it updates the macro variable AGE.
Your data step code is populating macro variables with names that are different from the dataset variable names.
So ... what is the question?
@Tom. So %SYSCALL SET () does not store the macro variable value for particular obs, keeps updating when new obs comes in? I think I got your point.
I was trying to capture the intermediate macro variable values.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.