DATA Step, Macro, Functions and more

%SYSCALL SET vs CALL SYMPUTX

Reply
Super Contributor
Posts: 285

%SYSCALL SET vs CALL SYMPUTX

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;
Super User
Super User
Posts: 9,866

Re: %SYSCALL SET vs CALL SYMPUTX

Posted in reply to SAS_inquisitive

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?

Super User
Posts: 13,950

Re: %SYSCALL SET vs CALL SYMPUTX

Posted in reply to SAS_inquisitive

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.

Super User
Super User
Posts: 8,290

Re: %SYSCALL SET vs CALL SYMPUTX

Posted in reply to SAS_inquisitive

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?

 

Super Contributor
Posts: 285

Re: %SYSCALL SET vs CALL SYMPUTX

[ Edited ]

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

Super Contributor
Posts: 285

Re: %SYSCALL SET vs CALL SYMPUTX

Posted in reply to SAS_inquisitive

I was trying to capture the intermediate macro variable values.

Ask a Question
Discussion stats
  • 5 replies
  • 272 views
  • 0 likes
  • 4 in conversation