BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I'm trying to resolve the error as mentioned below but I'm unable to do it. SCHDLD_OBJ_NM is the variable which I'm creating in the same datastep where I placed the below if condition and I was asked to achieve this one single step.

 

4219       if SCHDLD_OBJ_NM like %"_AP_"% then FNCTL_CMPNT_NM="AP" else "LIS";
                            ____                                     ____
                            388                                      388
                            202                                      202
ERROR 388-185: Expecting an arithmetic operator.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

4220       run;
3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

You use the Like Operator in a Where Statement. If you want to apply the logic in an If Statement, then read 

 

Sample 43303: Using the equivalent of CONTAINS and LIKE in an IF statement

Jagadishkatam
Amethyst | Level 16

You can also try IFC function

 

FNCTL_CMPNT_NM=ifc(indexw(SCHDLD_OBJ_NM,"_AP_"),'AP','LIS');
Thanks,
Jag
hashman
Ammonite | Level 13

@Babloo:

LIKE doesn't like IF, plus your double quotes are extraneous.

Use the FIND function instead. Also, if FNCTL_CMPNT_NM is a new variable not yet seen by the compiler, either declare it in the LENGTH statement as $3 beforehand or reverse the order in which the compiler sees "AP" and "LIS"; otherwise your "LIS" will be truncated to "LI" when "_AP_" is not found in SCHDLD_OBJ_NM:

if find (SCHDLD_OBJ_NM, "_AP_") = 0 then FNCTL_CMPNT_NM = "LIS" ;                                                                                                                                                                                               
else FNCTL_CMPNT_NM = "AP" ;                                         

Kind regards

Paul D.

   

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1087 views
  • 3 likes
  • 4 in conversation