BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,
This might be a simple question, I just want to write something like a where statement but with "if".

Made up example:

If variable_a like ('yes%maria') then tag='this is maria';
else if variable_a like ('yes%jose) then tag='this is jose';
else if .......................;

etc etc....

How is that possible?... what would work with an "if" statement?
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The construct you are suggesting (using LIKE, nor CONTAINS) is not supported with the IF statement of a DATA step. I am unfamiliar with the SAS-supported Perl regular expressions - others may have some input there?

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Yeah, I was wondering if there was something similar to Like or contains but couldn't find it for an IF statement.
Could I possibly trick it using a macro variable? constructing a macro variable that uses a "LIKE"?
..
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The use of a SAS macro variable has no effect other than being resolved at SAS compilation time. The use of LIKE is used with PROC SQL only, at least for now.

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Correction: SAS currently supports the WHERE clause (PROC SQL) and WHERE statement (PROC and DATA step), which in turn supports use of the LIKE and CONTAINS operators.

It's up to SAS users to voice their support for these types of features, through the SASWare Ballot system.

With reading the SGF paper (link below), apparently a Perl-like regular expression may be your answer. Digest at your own speed though! I tend to step away from the keyboard/cursor when it comes to Perl expressions.

Scott Barry
SBBWorks, Inc.

Workarounds for SASWare Ballot® Items
Jack Hamilton, First Health, West Sacramento, California USA
http://www2.sas.com/proceedings/sugi25/25/po/25p223.pdf
deleted_user
Not applicable
If you can't use where clause, you could try, as suggested by sbb, an array of keys with PRXPARSE and then lookup with PRXMATCH.
deleted_user
Not applicable
thank you all, I'll try these suggestions.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 1807 views
  • 0 likes
  • 2 in conversation