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
Explain how merging helps to combine data sets.
What is the role of unrestrictive users? : sas-grid-administration
how many types prompting framework can be broken down to? : Sas-bi
What is the function of output statement in a SAS Program?
What are the best sas programming practices for handling very large datasets? : sas-grid-administration
which date functions advances a date time or date/time value by a given interval? : Sas programming
What is the purpose of trailing @ and @@? How do you use them?
In SAS explain which statement does not perform automatic conversions in comparisons?
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.
what is slowly changing dimension? : Sas-di
what is null hypothesis? why do you consider that?
explain about sas business intelligence? : Sas-bi
how do the in= variables improve the capability of a merge? : Sas programming
what do the mod and int function do? What do the pad and dim functions do? : Sas programming
how the sas basic syntax style described? : Sas-administrator