BookmarkSubscribeRSS Feed
Sapkota
Calcite | Level 5

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

3 REPLIES 3
stat_sas
Ammonite | Level 13


Try this.

proc sql;

select * from have

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

quit;

ballardw
Super User

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.

Reeza
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 703 views
  • 1 like
  • 4 in conversation