I have a data set of 8600 records and i need to split the data set equally and create a flag for each group
Do you need 2 different tables?
Data one two ;
set have ;
if mod (_N_, 2) = 1 then
do ;
flag = 'ONE' ;
output one ;
end ;
else
do ;
flag = 'TWO' ;
output two ;
end ;
Run ;
Richard
No i only want the output in a single dataset with flags which are dividing the data.
For example if i have 8600 record i will have 860 in one flag='One'
860 is not half of 8600.
You should be able to work out what to do from my code, mostly by leaving out lines of code.
Richard
May be i was not clear.
I want to split the data of 8600 as 860 for each dataset *10 datasets.
%macro splitdata;
%do i=1 %to 8600 %by 860;
data want_&i.;
set have(firstobs=&i obs=%eval(&i+859));
flag="&i-%eval(&i+859)";
run;
%end;
%mend splitdata;
%splitdata
A simple method if you don't want a random split. This also avoids hard coding the number of observations.
%let groups=10;
data want;
set have nobs=nobs;
flag=ceil(_n_/(nobs/&groups.));
run;
Or simpler:
%let groups=10;
data want;
set have;
flag=mod(_n_-1, &groups.);
run;
PG
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.