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

I need to get the index of a macro value in another macro string.  findw seemed like it would work for this but it does not work with sysfunc.  I made an example below.

 

the code below sets varfind = 0 and varfinddata =3;  the warning message is:

WARNING: In a call to the FINDW function or routine, the modifier "'" not valid.

 quoting the space such as 

varfind = %sysfunc(findw("&testin","&count",%str(" "), %nrstr(%str('E')) ));

  does not seem to help.  what is failing when trying to use sysfunc?

 

 

 

%let testin =v vsd count f;
%let count =count;


%macro test();
    var="&testin";
    varfind = %sysfunc(findw(&testin,"&count",' ', 'E'));
    
    varfinddata=findw("&testin","&count", ' ', 'E');

%mend test;


data a;
%test
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
%let testin = v vsd count f;
%let count =count;
%let varfind = 0;

%let varfind = %sysfunc(findw(&testin, &count, %str(' ')  , e));
%put &varfind;

This works for me. 

 


@weg wrote:

I need to get the index of a macro value in another macro string.  findw seemed like it would work for this but it does not work with sysfunc.  I made an example below.

 

the code below sets varfind = 0 and varfinddata =3;  the warning message is:

WARNING: In a call to the FINDW function or routine, the modifier "'" not valid.

 quoting the space such as 

varfind = %sysfunc(findw("&testin","&count",%str(" "), %nrstr(%str('E')) ));

  does not seem to help.  what is failing when trying to use sysfunc?

 

 

 

%let testin =v vsd count f;
%let count =count;


%macro test();
    var="&testin";
    varfind = %sysfunc(findw(&testin,"&count",' ', 'E'));
    
    varfinddata=findw("&testin","&count", ' ', 'E');

%mend test;


data a;
%test
run;

 


 

View solution in original post

1 REPLY 1
Reeza
Super User
%let testin = v vsd count f;
%let count =count;
%let varfind = 0;

%let varfind = %sysfunc(findw(&testin, &count, %str(' ')  , e));
%put &varfind;

This works for me. 

 


@weg wrote:

I need to get the index of a macro value in another macro string.  findw seemed like it would work for this but it does not work with sysfunc.  I made an example below.

 

the code below sets varfind = 0 and varfinddata =3;  the warning message is:

WARNING: In a call to the FINDW function or routine, the modifier "'" not valid.

 quoting the space such as 

varfind = %sysfunc(findw("&testin","&count",%str(" "), %nrstr(%str('E')) ));

  does not seem to help.  what is failing when trying to use sysfunc?

 

 

 

%let testin =v vsd count f;
%let count =count;


%macro test();
    var="&testin";
    varfind = %sysfunc(findw(&testin,"&count",' ', 'E'));
    
    varfinddata=findw("&testin","&count", ' ', 'E');

%mend test;


data a;
%test
run;

 


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1038 views
  • 2 likes
  • 2 in conversation