BookmarkSubscribeRSS Feed
HitmonTran
Pyrite | Level 9

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' =: '_').

HitmonTran_1-1587838819474.png

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!

 

 

1 REPLY 1
Tom
Super User Tom
Super User

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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1265 views
  • 1 like
  • 2 in conversation