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

Explain how merging helps to combine data sets.

618


What is the role of unrestrictive users? : sas-grid-administration

572


how many types prompting framework can be broken down to? : Sas-bi

635


What is the function of output statement in a SAS Program?

616


What are the best sas programming practices for handling very large datasets? : sas-grid-administration

570






which date functions advances a date time or date/time value by a given interval? : Sas programming

538


What is the purpose of trailing @ and @@? How do you use them?

613


In SAS explain which statement does not perform automatic conversions in comparisons?

802


data data1; input dt account; format dt date9.; cards; 1745 1230 1756 1120 1788 1130 1767 1240 ; data data2; input startdt enddt total; format startdt date9. enddt date9.; cards; 1657 1834 12300 1557 1758 16800 1789 1789 12300 1788 1345 12383 1899 1899 13250 ; proc sql; create table data3 as select * from data1 as x left join data2 as y on x.dt>=y.startdt and x.dt<=y.enddt; quit; Here, we are getting cartision product. But,I want left join report consisting of this program. It should not get duplicate values. you can modify the program also.

1802


what is slowly changing dimension? : Sas-di

626


what is null hypothesis? why do you consider that?

2419


explain about sas business intelligence? : Sas-bi

598


how do the in= variables improve the capability of a merge? : Sas programming

935


what do the mod and int function do? What do the pad and dim functions do? : Sas programming

617


how the sas basic syntax style described? : Sas-administrator

608