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

I got errors with the following IF/Then statement.

 

if POSTAL_CODE like "T__" and AREA_CODE in ("368", "403", "587", "780", "825") then
	PROVINCE="AB";
ERROR 388-185: Expecting an arithmetic operator.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
 
Does that mean I cannot use wild cards in the conditional statement? What code should I put to check if the first char of the string is 'T' ? 
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

The LIKE operator is not valid within an IF condition. Here what you can use instead.

View solution in original post

4 REPLIES 4
mkeintz
PROC Star

The LIKE operator is not available in the DATA step, except as a WHERE condition.

 

But you can do something like (no pun intended):

 

 

if POSTAL_CODE =: 'T' and AREA_CODE in ("368", "403", "587", "780", "825") then PROVINCE="AB";

the =: relation take the shorter of the two expressions and sees if the other expression starts with matching characters.  In this case it test whether postal_code starts with a 'T',

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Patrick
Opal | Level 21

The LIKE operator is not valid within an IF condition. Here what you can use instead.

MLAC
Fluorite | Level 6

Thanks. That helps. But the output of the second part on that page is wrong.  The output should like this:

Diana
Diane
DIANNA

ballardw
Super User

@MLAC wrote:

Thanks. That helps. But the output of the second part on that page is wrong.  The output should like this:

Diana
Diane
DIANNA


Example data of the input to get that output and the actual code you used.

 

If referring to the example link that @Patrick showed then I submit that you really show the code that you ran as that is the exact result I get with the data. Note that depending on what you did it may be that your code modified the input set because unfortunately the example code is using the

data test;
   set test;

construct repeatedly. And each one completely rewrites the set Test. So if you played around with the code for the first example, such as the  

   /* the syntax to select observations that /*
   /*  do not match the pattern is below */
   *if name not =: 'D';

then you may have removed the values that are expected for the second part.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 862 views
  • 0 likes
  • 4 in conversation