Help using Base SAS procedures

If and Contains or sounds like

Reply
N/A
Posts: 0

If and Contains or sounds like

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?
Super Contributor
Super Contributor
Posts: 3,174

Re: If and Contains or sounds like

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.
N/A
Posts: 0

Re: If and Contains or sounds like

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"?
..
Super Contributor
Super Contributor
Posts: 3,174

Re: If and Contains or sounds like

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: If and Contains or sounds like

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
N/A
Posts: 0

Re: If and Contains or sounds like

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.
N/A
Posts: 0

Re: If and Contains or sounds like

thank you all, I'll try these suggestions.
Ask a Question
Discussion stats
  • 6 replies
  • 157 views
  • 0 likes
  • 2 in conversation