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.
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 ....
Find returns 0 if the string was not found, so results matches exactly your code.
ok, may I know how can I tweak the condition to get the desired results?
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;
I ran the code below and got the Output as "DATA TRANSFER" instead of "DATA LOADER" for the variable SOLN_CMPNT_NM
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 ....
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.
It's working If I remove the underscore.
@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 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.