BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

 

If I execute the below code, I'm not getting the right value for the variable SOLN_CMPNT_NM. I'm getting the value as "DATA EXPORT" instead of "DATA TRANSFER" when my &etls_jobName resolves 

I'm not certin what I'm doing wrong here.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Babloo 

Using FIND() and not FINDW() appears to be the correct function for what you're doing.

As @andreas_lds already wrote: The FIND() function returns 0 if a sub-string is not found in a string. If a sub-string is found then it returns the position where the substring starts in the string. Soo.... Your conditions need to be: 

if find(....) > 0 then...

 

If you want to use FINDW() then don't use the underscore as part of your sub-string you search for but add it as 3rd parameter which defines the characters that are word delimiters.

if findw("&etls_jobName","TRA",'_') > 0 then ....

View solution in original post

8 REPLIES 8
andreas_lds
Jade | Level 19

Find returns 0 if the string was not found, so results matches exactly your code.

Babloo
Rhodochrosite | Level 12

ok, may I know how can I tweak the condition to get the desired results?

Jagadishkatam
Amethyst | Level 16

Please try to use findw instead of find

 

%let etls_jobName=J_PAC_TRA_INSURANCE_CONTRACT_GROUP;
data metadata;
FNCTL_CMPNT_NM=ifc(indexw("&etls_jobName","_ADP_"),'ADP','LDIS');
if findw("&etls_jobName","_TRA_") = 0 
then SOLN_CMPNT_NM= "DATA TRANSFER" ;           
else if findw("&etls_jobName","_EXPORT") = 0 
then SOLN_CMPNT_NM = "DATA EXPORT" ; 
else if findw("&etls_jobName","_LOA_") = 0 
then SOLN_CMPNT_NM = "DATA LOADER" ; 
else if SOLN_CMPNT_NM = "DATA IMPORT" ; 
run;
Thanks,
Jag
Babloo
Rhodochrosite | Level 12

I ran the code below and got the Output as "DATA TRANSFER" instead of "DATA LOADER" for the variable SOLN_CMPNT_NM

 

Patrick
Opal | Level 21

@Babloo 

Using FIND() and not FINDW() appears to be the correct function for what you're doing.

As @andreas_lds already wrote: The FIND() function returns 0 if a sub-string is not found in a string. If a sub-string is found then it returns the position where the substring starts in the string. Soo.... Your conditions need to be: 

if find(....) > 0 then...

 

If you want to use FINDW() then don't use the underscore as part of your sub-string you search for but add it as 3rd parameter which defines the characters that are word delimiters.

if findw("&etls_jobName","TRA",'_') > 0 then ....

Babloo
Rhodochrosite | Level 12

Thanks, now I could get the desired output but also I could see the warning message in the log as below. Could you please tell me how to get rid of this warning?

 

878       /*Solution Component Name derivation*/
2879       if find("&etls_jobName","INPUT",'_') > 0
2880       then SOLN_CMPNT_NM= "DATA IMPORT";
2881       else if find("&etls_jobName","EXPORT",'_') > 0
2882       then SOLN_CMPNT_NM = "DATA EXPORT" ;
2883       else if find("&etls_jobName","LOA",'_') > 0
2884       then SOLN_CMPNT_NM = "DATA LOADER" ;
2885       else if find("&etls_jobName","TRA",'_') > 0
2886       then SOLN_CMPNT_NM = "DATA TRANSER" ;
2887       else SOLN_CMPNT_NM = "OTHER" ;
2888       /*Job return code*/
2889       %PUT &SYSRC.;
0
2890       run;

WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
WARNING: In a call to the FIND function or routine, the modifier "_" not valid.
Babloo
Rhodochrosite | Level 12

It's working If I remove the underscore.

Patrick
Opal | Level 21

@Babloo wrote:

It's working If I remove the underscore.


Yes, because the underscore as 3rd parameter is for the findW() function and not the find() function.

sas-innovate-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 8 replies
  • 6160 views
  • 3 likes
  • 4 in conversation