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

how we can create a FLAG datasets? Ex:-ID age_group no_persons 1 to 10 10 to 20 3 11 to 20 21 to 30 7 21 to 3o 31 to 40 5

1878


What are the statements in proc sql?

807


Differentiate between proc means and proc summary.

789


What is interleaving in SAS?

866


Mention the difference between ceil and floor functions in sas?

903


How do you delete duplicate observations in sas?

814


describe how to adjust the performance of data integrator? : Sas-di

770


How does SAS handle missing values in: assignment statements, functions, a merge, an update, sort order, formats, PROCs?

1317


what is change analysis in sas di ? : Sas-di

802


what is the purpose of _error_? : Sas programming

858


how could you generate test data with no input data? : Sas programming

890


what is snowflake schema? : Sas-di

907


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

1050


What is the use of the %include statement?

901


What would you change about your job?

2142