hay, i have some problem. i want to looping all macro, and expected output is i have 3 dataset output from proc freq (test_education ; test_residence and test_monthly_income)
but my code works for the last variable in macro %LET (monthly_income)..
is it possible to me if i want to automatically create 3 dataset in row.. how is it possible? is my sas code is wrong?
thanks
sorry for my bad english.. here i attach the code...
%macro infoid(data,xvar,yvar);
data _null_;
if 0 then set &data.;
array _x
array _y
call symput("nx", trim(left(put(dim(_x),12.))));
call symput("ny", trim(left(put(dim(_y),12.))));
length _mname _vname $20;
do _i=1 to dim(_x);
_mname='x'||trim(left(put(_i,12.)));
call execute('%global '||_mname);
call vname(_x[_i],_vname);
call symput(_mname,trim(_vname));
end;
do _i=1 to dim(_y);
_mname='y'||trim(left(put(_i,12.)));
call execute('%global '||_mname);
call vname(_y[_i],_vname);
call symput(_mname,trim(_vname));
end;
stop;
proc sort data=&data.(keep= &&x&nx gbi ) out=test_&&x&x;
by &&x&nx;
run;
%mend;
%let xvar = education_level residence monthly_income ;
%infoid(&xvar,gbi);
I'm confused, you have three parameters in the macro definition, but you only seem to use two of them, and I guess that your &xvar will be received as &data - is that what you want?
There is no actual macro loop coded in that macro.
It looks like you want to put the PROC SORT step inside of a %DO loop.
Hi,
If I've understood your macro function definition it processes one data set only, so maybe you could call your macro 3 times, each time supplying the different data set name.
To automatically loop through a space-separated list of data set names then you could use something like the following, based on code supplied by @Tom:
%macro infoid_loop(datalist);
%local i date ;
%do i=1 %to %sysfunc(countw(&datalist,%str( )));
%let dataset=%scan(&datalist,&i,%str( ));
%infoid(&dataset,arg2,arg3);
%end;
%mend infoid_loop;
Then invoke it:
%infoid_loop(set_a set b set_c,arg2,arg3);
One thing I noticed is that your macro function definition allows 3 parameters to be passed to it:
%macro infoid(data,xvar,yvar);
but you are only calling it with 2 parameters:
%infoid(&xvar,gbi);
If you are still having problems then please post the log with any error messages showing.
Regards,
Amir.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.