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;
%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;
%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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.