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.
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.
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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.