How to select the observations randomly from a SAS dataset

Answer Posted / srikanth

you can use the RANUNI function to select observations
randomly.

Ex:-

data test;
input number @@;
cards;
2.1 3.1 4 6 2.2 4.9 4 5 3 3.3 4 5 3 4.3 5 7 3 3 9 11
;

data test1;
set test;
random=ranuni(1);
run;

%let k=10;

PROC SORT DATA=TEST1;
BY random;/*SORT OBSERVATIONS*/
run;

DATA TEST2;
SET TEST2 (DROP=RANDOM);
IF _N_ LE &K;
RUN;

PROC PRINT ;
RUN;

Is This Answer Correct ?    8 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe a time when you were really stuck on a problem and how you solved it?

2207


what is sas database server? : Sas-di

619


How substr function works in sas?

705


List down the reasons for choosing sas over other data analytics tools.

815


How long can a macro variable be? A token? : sas-macro

721






What is the difference between INPUT and INFILE ?

760


Explain the use of proc print and proc contents?

562


What is the purpose of _character_ and _numeric_?

593


What is factor analysis?

667


explain the key concept of sas? : Sas-administrator

563


What are the 3 components in sas programming?

729


What are the five ways to do a table lookup in sas? : sas-grid-administration

601


how does sas handle missing values in functions? : Sas programming

606


what is sas metadata server? : Sas-di

597


I have 3 years of work experience at a startup and recently got certified in Data Science with SAS. I need to know how to get into the analytics industry

1331