BookmarkSubscribeRSS Feed
Bipingaud
Calcite | Level 5

Hii, can any one plz tell how can we retrieve a single random observation(row) from a data set?

3 REPLIES 3
Shmuel
Garnet | Level 18

you can use:

    set input(obs=1, firstobs=) ;  /* change firstobs to any row number you want */

BrunoMueller
SAS Super FREQ

Hi

 

You can use some options on the SET statement to achieve this, see example below. Please be aware when using the POINT= option, you also need a STOP statement, as otherwise the DATA Step will loop. Have a look in the doc at the description of the POINT= and NOBS= options. The variable name used in the POINT= option is not written to the output dataset, this is why I use two variables.

 

data want;
  getObs = ceil( ranuni(0) * numObs);
  _getObs = getObs;
  set sashelp.cars point=_getObs nobs=numObs;
  output;
  stop;
run;

Also look at Proc SURVEYSELECT for more sophisticated ways to get a random sample from a SAS data set

 

Bruno

Ksharp
Super User

proc surveyselect data=sashelp.class out=want sampsize=1;
run;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3081 views
  • 3 likes
  • 4 in conversation