Hi All,
I have an excel spread sheet that adds new column every week. I want to create an efficient program where I don't need to manually add new columns every week into the program, but rather hit the "run" button.
This is what I had in mind. Let me know if it possible to execute these steps:
1. use Proc Contents to collect the variable names
2. use callsymput to create a macro of these variable names
3. create a local macro and calling these parameters with the callsymput values.
Here is an example:
Proc contents (only want 'NAME' =: '_').
proc contents data=instagram out=contents; run;
data outty;
set contents (where=(name=:'_'));
run;
data _null_;
set outty;
call symput('u'||strip(put(varnum,best.)), strip(name));
run;
%put &u1 &u2 &u3 &u4 &u5 &u6 &u7; /**how would i make this efficient without adding each week***/
%macro val (no=,aval=);
data one&no.;
set instagram;
col="&aval";
values=&aval;
output;
keep col values;
run;
%mend val;
%val (no=1,aval=_brand_a); /***how would i use the callsymput here without adding new macro calls every week**/
%val (no=2,aval=_brand_b);
%val (no=3,aval=_brand_c);
THank you!
The easiest way is to skip the macro variable(s) and call the macro directly from the dataset that has the names already.
data outty;
no+1;
set contents ;
where name=:'_' ;
call execute(cats('%nrstr(%val)(no=',no,',aval=',name,')'));
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: