i have dataset of 6 variabes and 100 observations,if i want to create 5 datasets with minimum 26 observations from the existing dataset...how i can generate ?
I would agree with @Reeza if you are trying to gather sample data sets, I would suggest utilizing the surveyselect procedure, as it will gather random samples of data. You could do something like the following to ensure you don't have the same observations in each of the six data sets:
proc surveyselect data=have out=want1
method=srs n=26;
run;
proc sql;
create table remain1 as
select A.*
from have A left join want1 B
on (A.ID=B.ID)
Where B.ID="";
quit;
proc surveyselect data=remain1 out=want2
method=srs n=26;
run;
proc sql;
create table remain2 as
select A.*
from remain1 A left join want2 B
on (A.ID=B.ID)
Where B.ID="";
quit;
.
.
.
However, if you want to just create six different data sets with 26 observations in each (sequentially) the following code would do it:
data want1;
set have nobs=26;
run;
data want2;
set have (firstobs=27 obs=26);
run;
data want3;
set have (firstobs=54 obs=26);
run;
data want4;
set have (firstobs=81 obs=26);
run;
data want5;
set have (firstobs=108 obs=26);
run;
data want6;
set have (firstobs=135 obs=26);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.