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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;

data _null_;
   result=findw("&variablenames.","CCC"," ","E");
   put result=;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20
%let variablenames = AAA BBB CCC DDD EEE FFF GGG;

data _null_;
   result=findw("&variablenames.","CCC"," ","E");
   put result=;
run;
tonoplast
Obsidian | Level 7

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

PeterClemmensen
Tourmaline | Level 20

Ah ok 🙂 Anyway, glad you found your answer

ballardw
Super User

@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.

tonoplast
Obsidian | Level 7

Thank you! This is great!