BookmarkSubscribeRSS Feed
luca87
Obsidian | Level 7

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

3 REPLIES 3
luca87
Obsidian | Level 7

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;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
FreelanceReinh
Jade | Level 19

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 3 replies
  • 513 views
  • 1 like
  • 3 in conversation