BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,
By making connection to a database in SAS, I can select particular columns from a table and this process continues for a set of time periods and all data is meged. Now I want to select a random generated ID's for each and every row that was selected, when I query the final data set.

How to get this?

thanks,
3 REPLIES 3
deleted_user
Not applicable
Hope I understand what your after.

One way:

DATA two;
SET one;
id = Uniform(0); * this will generate pseudo random numbers;
RUN;

* sort on the random numbers;
PROC SORT DATA=two;
BY id;


DATA three;
SET two(OBS=100); *** pick 100 "random" observations ;
RUN;

If you have the STAT package, PROC SURVEYSELECT is excellent and very versatile.
.
The above could be replaced by the following:

PROC SURVEYSELECT DATA=one METHOD=srs N=100 OUT=three;
RUN;
deleted_user
Not applicable
That worked, but giving random numbers.

I used id=_N_, which gave observation number as id.

thanks,
deleted_user
Not applicable
Also, below one worked:

id1='000'||left(put(_N_,best10.))

thanks

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!

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.

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
  • 649 views
  • 0 likes
  • 1 in conversation