I want to divide up a population into cohorts of subpopulations where I have the numbers in a macro var.
data Population;
do ids = 1 to 100000;
output;
end;
;
run;
proc sql noprint;
select ceil(count(*)/7500)
into :cohort
from Population;
quit;
%put &cohort;
%macro test;
%do i = 1 %to &cohort;
proc sql noprint;
select distinct ids
into :KSIds
from Population(firstobs = &i cohort = &i);
quit;
%end;
%mend;
First I am finding out how many cohorts I need, then I am trying to get a macro to write no more than 7500 KSids from the Population file into the KSIds0, KSIds1. KSids2 etc
I just
Macros not needed, this can be done in a data step
data cohorts;
set population;
cohort = floor((ids-1)/7500);
run;
I think I am misunderstood, (my poor explanation to blame)
I want the ids to be in a list
each macro containing ids
first cohort : id 1-7500
second cohort: id 7501-15000
@Kiteulf wrote:
I think I am misunderstood, (my poor explanation to blame)
I want the ids to be in a list
each macro containing ids
first cohort : id 1-7500
second cohort: id 7501-15000
I don't know why you need them in a separate list, or actually many separate lists, when they are clearly identified in the data set I named COHORT.
What would you do with these macro variable lists once you have it? Please explain the next step. I'm relatively sure that the data set COHORT can provide what you need. Whatever the next step is, I don't think you need macro variables containing long lists of IDs.
Or as a variant to what @PaigeMiller proposes.
data Population;
do ids = 1 to 100000;
output;
end;
stop;
run;
data cohorts;
set population;
cohort = mod(_n_,7500)+1;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.