09-14-2017 09:47 AM
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;
09-14-2017 09:51 AM
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?
09-14-2017 10:16 AM
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.
09-14-2017 10:31 AM
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?
09-14-2017 10:46 AM - edited 09-14-2017 10:49 AM
@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.