Hi, I have this code:
%let path=prova/qa/luca;
data _null_;
if findw("&path.",'/qa/','/')=1
then run_build = 1;
else if findw("&path.",'/prod/','/')=1 then run_build = 1;
else run_build = 0;
call symputx('run_build',run_build);
run;
%put &=run_build;
I have to search exactly '/qa/' or '/prod/' and then I expect 1 as a result of run_build, but I get 0.
How can I do it?
Thanks
Luca
with index seems to work
data _null_;
if index("&path", "/qa/") > 0
then run_build = 1;
else if index("&path", "/prod/") > 0 then run_build = 1;
else run_build = 0;
call symputx('run_build',run_build);
run;
%put &=run_build;
I'm not sure why you are using FINDW, I don't think that will work here, but FIND works properly. Also, you want to test to see if the result of FIND is greater than 0, you do not want to test if the result of FIND=1. FIND returns the position in &path where the target characters are found, and if you test to see if it equals 1, that is the same as testing if the target string is at the BEGINNING of &path.
Hi @luca87,
In addition to the issue with the return value of FINDW (as pointed out by Paige Miller), you should not include the delimiters in the search string. So the whole DATA step could be simplified to this:
data _null_;
call symputx('run_build', findw("&path.",'qa','/') | findw("&path.",'prod','/'));
run;
Or this, if you want to switch to FIND (or similarly to INDEX) and then include the delimiters in the search string:
data _null_;
call symputx('run_build', find("&path.",'/qa/') | find("&path.",'/prod/'));
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.