Hello Experts,
I need to split my larger data set. I know how many datasets i want from the larger data set.
I want to split my larger data set into 3 data set with equal count(if total observation is completely divisible by 3) or else higher observation count in first data set
Using this code i am achieving the result.
%macro temp(dataset=,noofsplits=);
data %do i=1 %to &noofsplits.; split&i. %end;; retain x; set &dataset. nobs=nobs;
if _n_ eq 1 then do; if mod(nobs,&noofsplits.) eq 0 then x=int(nobs/&noofsplits.); else x=int(nobs/&noofsplits.)+1; end;
%do i=1 %to &noofsplits; %if &i. > 1 %then %do; else %end;
if _n_ le (&i.*x) then output split&i.; %end; run; %mend temp; %temp(dataset=sashelp.cars , noofsplits=3);
SASHELP.CARS has 428 observations. So i am getting 143 in first data set and 143 in second data set and 142 in third data set. But, this part of code i am not understanding clearly %if &i. > 1 %then %do; else %end;
If we remove these lines from my code means totally it collapse(143 in first data set and 286 in second data set and 428 in third data set). It's clear that it used to start the observation from the next obs of completed data set. I am not getting how it is done.
It will be very helpful if some one clarify this for me and if there is any easier way to achieve the same without hard coding total data set needed means most welcome
Thanks in Advance
... View more