Hi Experts,
I need to create an automation system for creating subsets based on number of observations present in master dataset. For example: if my master dataset has 100 observations, I need to create 4 subsets each having 25 observations. I am unable to think of a logic. If my master dataset has 200 observations then I need to create 4 datasets of 50 observations each. Please help me in writing this logic.
Thank you,
Gurpreet
Get number of observations, then run code, e.g:
proc sql noprint;
select nobs/4
into :cnt
from dictionary.tables
where libname="<yourlib>"
and memname="<yourdataset>";
quit;
data want1 want2 want3 want4;
set <yourlib>.<yourdataset>;
if _n_ < (1 * &cnt.) then output want1;
else if _n_ < (2 *&cnt.) then output want2;
...;
run;
If your data source is a SAS data set, you can pull the number of observations and divide them up in the same step:
data subset1 subset2 subset3 subset4;
set have nobs=_nobs_;
if _n_ <= _nobs_ / 4 then output subset1;
else if _n_ <= _nobs_ / 2 then output subset2;
else if _n_ <= _nobs_ * 3 / 4 then output subset3;
else output subset4;
run;
proc surveyselect data=sashelp.air out=want group=4;
run;
Nice, I always forget the surveyselect function - even though I posted on it some time back myself 🐵
ME TOO !
remember and forget something everyday .
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.