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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.