Dear SAS community,
I am struggling to find the answer to something that may be a simple thing. Please help.
I have a macro variable:
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;
If I want to find what position of CCC which will show as 3. How can I achieve this?
Thank you for your help.
Regards,
T
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;
data _null_;
result=findw("&variablenames.","CCC"," ","E");
put result=;
run;
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;
data _null_;
result=findw("&variablenames.","CCC"," ","E");
put result=;
run;
Thank you very much! This was what I was looking for!
I didn't specify but I wanted to put it in a separate macro variable, so I added some lines to your code.
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;
data _null_;
result=findw("&variablenames.","CCC"," ","E");
put result=; call symput("thisnum",result);
run;
%put thisnum = &thisnum;
Regards,
T
Ah ok 🙂 Anyway, glad you found your answer
@tonoplast wrote:
Thank you very much! This was what I was looking for!
I didn't specify but I wanted to put it in a separate macro variable, so I added some lines to your code.
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;
data _null_;
result=findw("&variablenames.","CCC"," ","E");
put result=; call symput("thisnum",result);
run;%put thisnum = &thisnum;
Regards,
T
You can use the macro function %sysfunc to call data step functions
%let thisnum = %sysfunc(findw(&variablenames.,CCC,%str(' ') ,E));
%put &thisnum.;
Note that the quotes are needed in the macro language except when a specific blank is needed for some functions.
Thank you! This is great!
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.