BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

gnet wrote:

Hi there,

This is a fascinating bit of code, and involves hash programming that I've never used. Looks like I have work to do!

Thanks again!

" Looks like I have work to do!" hmmm me too. That makes two of us. 🙂

 

Trick to be successful

1. Stay updated with posts from Tom, Art T, Xia Keshan, Mkeintz, Astounding, Reeza, Steve denham, Kurt, PG, Haikuo, Friedegg et al. They make our lives a whole lot easier. That's how I learn. 


 

Tom
Super User Tom
Super User

Not sure what the macro has to do with the problem. But if you want to generate code then first generate the code to a file and then use %INCLUDE to make it part of your data step.

proc sort data=in(keep=x) out=xlist nodupkey;
  by x ;
run;

filename code temp;
data _null_;
  set xlist end=eof;
  file code ;
  if _n_=1 then put 'select (x);' ;
  put 'when (' x :$quote. ') rc=%vtest(' x ');' ;
  if eof then put 'end;' ;
run;

options mprint;
data want ;
  set in ;
%include code / source2 ;
run;

Result.

 

1271  options mprint;
1272  data want ;
1273    set in ;
1274  %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\...\#LN00069.
1275 +select (x);
1276 +when ("a" ) rc=%vtest(a );
MPRINT(VTEST):  0 +a_1 +a_2 +a_3
1277 +when ("b" ) rc=%vtest(b );
MPRINT(VTEST):  0 +b_1 +b_2 +b_3
1278 +when ("c" ) rc=%vtest(c );
MPRINT(VTEST):  0 +c_1 +c_2 +c_3
1279 +end;
NOTE: %INCLUDE (level 1) ending.
1280  run;

NOTE: There were 3 observations read from the data set WORK.IN.
NOTE: The data set WORK.WANT has 3 observations and 11 variables.

 

gnet
Calcite | Level 5

Hi Tom,

This is the idea that I was going for. I hadn't considered this approach to writing the code into a file and then running with %include inside the datastep.

 

Thanks!

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
  • 17 replies
  • 8222 views
  • 2 likes
  • 7 in conversation