Help using Base SAS procedures

Creating a subset file with selected ID

Reply
Contributor
Posts: 32

Creating a subset file with selected ID

I would like to subset one dataset so that my output file has only the desired ID numbers. For an example, from a file with the following ID (plus other variables) I would

like to have a subset file that contains only the ID = 122142, 321212, 123213, 113211, 123131, 232116. Please help.

Sapkota

ID

122142

321212

123213

113211

123131

232116

665454

465653

543543

434536

094345

098543

934543

436344

and so on

Trusted Advisor
Posts: 1,204

Re: Creating a subset file with selected ID


Try this.

proc sql;

select * from have

where id in (122142, 321212, 123213, 113211, 123131, 232116);

quit;

Super User
Posts: 10,529

Re: Creating a subset file with selected ID

If they are character variables and not numeric you'll to quote each value:

in ('122142', '321212', etc)

the commas are optional in later versions of SAS but I think help readability of  the code.

Super User
Posts: 17,899

Re: Creating a subset file with selected ID

If you're new to SAS, the SAS tutorials on the UCLA website are a great resource.

SAS Learning Module: Subsetting data in SAS

SAS Class Notes: Managing Data

Ask a Question
Discussion stats
  • 3 replies
  • 175 views
  • 1 like
  • 4 in conversation