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";
The LIKE operator is not valid within an IF condition. Here what you can use instead.
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 LIKE operator is not valid within an IF condition. Here what you can use instead.
Thanks. That helps. But the output of the second part on that page is wrong. The output should like this:
Diana
Diane
DIANNA
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.