Hello all,
I have a data sets that I'd like to to a proc with and I want to loop through the columns
looks like this
apple | orange | seeds | red | |
obs1 | 12 | 12 | 12 | 12 |
obs2 | 2 | 2 | 2 | 2 |
obs3 | -8 | -8 | -8 | -8 |
what I wanted to do is this
%do i=1 to end;
proc glm;
model y=&varlist&i;
quit;
%end;
so I can run the proc against each of the variable in my variable list.
I can easily create the &varlist. using proc sql, but I wanted to run the proc glm on each of the vaeriable list (not all of them)
can anyone show me how to create this &varlist&i?
use symput?
Thank you!
More explicitly,
%let names=Susan Mary Alice Zeta Queen......Evin;
I wanted to have sometime embeded with it, say &i.
so I can have names get recognized as &&list.&i, e.g. &names1.=susan &names2.=Mary, &names3.=zeta, &names4.=Queen and so on.
a extended quesiton will be, is there any doc that I can find such tutorial or logic to build such mechanism for broder &&&type of marco use?
Thank you!!
Let's suppose this is your starting point:
%let names=Susan Mary Alice Zeta Queen......Evin;
Inside a macro, you can add code like this to split &NAMES into separate variables:
%do i=1 %to %sysfunc(countw(&names));
%let name&i = %scan(&names, &i, %str( ));
%end;
While this can be done, it also can add unnecessary complexity to the subsequent processing. So it's a choice you need to make.
That's a common enough question .... here's a link:
See the example on this page, under:
http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/
Thank you!
Thank you, I actually saw this solution before I posted my question.
This works but I was looking more for that how to create indexes for my macro variable contains multiple variables names in there.
for example,
%let names=Susan Mary Alice Zeta Queen......Evin;
I wanted to have sometime embeded with it, say &i.
so I can have names get recognized as &&list.&i, e.g. &names1.=susan &names2.=Mary, &names3.=zeta, &names4.=Queen and so on.
a extended quesiton will be, is there any doc that I can find such tutorial or logic to build such mechanism for broder &&&type of marco use?
Thank you!!
Can you show exactly what code the macro is supposed to generate for a given macro variable containing a list?
How you are actually using things helps provide better responses.
Thank you for getting back to me. I just had it answered below.
I appreciate your help and hope to learn again from you next time!
Let's suppose this is your starting point:
%let names=Susan Mary Alice Zeta Queen......Evin;
Inside a macro, you can add code like this to split &NAMES into separate variables:
%do i=1 %to %sysfunc(countw(&names));
%let name&i = %scan(&names, &i, %str( ));
%end;
While this can be done, it also can add unnecessary complexity to the subsequent processing. So it's a choice you need to make.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.