BookmarkSubscribeRSS Feed
SAS_inquisitive
Lapis Lazuli | Level 10

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;
5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

ballardw
Super User

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.

Tom
Super User Tom
Super User

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?

 

SAS_inquisitive
Lapis Lazuli | Level 10

@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.

SAS_inquisitive
Lapis Lazuli | Level 10

I was trying to capture the intermediate macro variable values.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2053 views
  • 0 likes
  • 4 in conversation