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

Im creating a table from a larger data set, and I know there must be a more efficient way to do this.  I need to select patients between the age of 2 and 13 with a diagnosis "493XX" in the DX1, DX2,DX3 or DX4 variable field.  Right now, I'm doing this in 2 tables-- 1st grabing the age group I need, and then in a seperate data step, searching the DX from that table.

 

data need1_C1407;

set have_ C1407;

where Patage between 2 and 13;

run;

 

data need_AD1407;

set need1_C1407;

where dx1 like '493%' or

dx2 like '493%' or

dx3 like '493%' or

dx4 like '493;

run;

 

I've tried doing this in one step, but I keep getting an error.  Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

In addition to Reeza's suggestion, the program would be slightly faster to switch from " like " to " =: ".  In combination, the result might look like this:

 

data want;

set have;

where (2 <= Patage <= 13)

and (dx1 =: '493' or dx2 =: '493' or dx3 =: '493' or dx4 =: '493');

run;

 

(Looks like great minds think alike, and perhaps at the same time!)

View solution in original post

4 REPLIES 4
Reeza
Super User
Post what you've tried that generates the error.

You should be able to combine them with an AND and appropriate brackets.
ballardw
Super User

"Like" is an SQL function, not datastep.

 

If you DX codes are character try:

 

DX1 =: "493" or ... 

 

The =: is "starts with"

Astounding
PROC Star

In addition to Reeza's suggestion, the program would be slightly faster to switch from " like " to " =: ".  In combination, the result might look like this:

 

data want;

set have;

where (2 <= Patage <= 13)

and (dx1 =: '493' or dx2 =: '493' or dx3 =: '493' or dx4 =: '493');

run;

 

(Looks like great minds think alike, and perhaps at the same time!)

jenim514
Pyrite | Level 9

This syntax worked well.  Thank you!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1172 views
  • 2 likes
  • 4 in conversation