I'm interested in developing a macro that can split a table into 4 datasets proportional to the size of the input table. Four tables with an equal (or roughly equal) number of records. So to create a macro that takes a table and breaks it up into 4 based on the size of the input table. So for a table with 100,000 records, I'd want it to break it into 4 tables with 25,000 records each.
data
want1
want2
want3
want4
;
set have;
select (mod(_n_,4));
when (0) output want1;
when (1) output want2;
when (2) output want3;
when (3) output want4;
end;
run;
I guess it can be seen how this step can be made dynamic.
data
want1
want2
want3
want4
;
set have;
select (mod(_n_,4));
when (0) output want1;
when (1) output want2;
when (2) output want3;
when (3) output want4;
end;
run;
I guess it can be seen how this step can be made dynamic.
Hi @PegaZeus,
Just to add a variant of Kurt Bremser's solution: With two modifications to his code you can achieve a partition into four blocks of consecutive observations of dataset HAVE (first, second, third and fourth quarter):
set have nobs=n; select (int(4*(_n_-1)/n));
Edit: If you use this in a macro, you should name variable n differently, e.g. ___n, or dynamically in order to avoid name conflicts with a possibly existing variable n in dataset HAVE.
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.