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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.