DATA Step, Macro, Functions and more

subsetting multiple rows in a dataset

Accepted Solution Solved
Reply
Contributor
Posts: 48
Accepted Solution

subsetting multiple rows in a dataset

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


Accepted Solutions
Solution
‎09-22-2016 09:32 AM
Super User
Posts: 5,498

Re: subsetting multiple rows in a dataset

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


All Replies
Super User
Posts: 7,762

Re: subsetting multiple rows in a dataset

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎09-22-2016 09:32 AM
Super User
Posts: 5,498

Re: subsetting multiple rows in a dataset

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.

Super User
Posts: 5,424

Re: subsetting multiple rows in a dataset

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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