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!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1058 views
  • 4 likes
  • 3 in conversation