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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1184 views
  • 0 likes
  • 1 in conversation