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

I am wondering how to subset multiple rows in a dataset in SAS, any codes recommended? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Take a look at the WHERE statement.  That's a common tool for the task, and can be used in both DATA and PROC steps.  Its chief limitation is that it must base the subsetting decisions on variables that already exist in the incoming data set.

 

If you need to perform calculations first, and base the subsetting on the calculated values, take a look at the IF statement.  (Not IF/THEN.)  It's valid in a DATA step only.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Please supply some example "have" and "want" data rows to illustrate your question.

Subsetting datasets as such is a very easy task, so you seem to have some additional requirements.

Astounding
PROC Star

Take a look at the WHERE statement.  That's a common tool for the task, and can be used in both DATA and PROC steps.  Its chief limitation is that it must base the subsetting decisions on variables that already exist in the incoming data set.

 

If you need to perform calculations first, and base the subsetting on the calculated values, take a look at the IF statement.  (Not IF/THEN.)  It's valid in a DATA step only.

LinusH
Tourmaline | Level 20

Another option if you wish to subset based on a list of values: use SQL inner join/sub-query with a look-up table.

Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1917 views
  • 2 likes
  • 4 in conversation