BookmarkSubscribeRSS Feed
Kiteulf
Quartz | Level 8

 

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 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Macros not needed, this can be done in a data step

 

data cohorts;
    set population;
    cohort = floor((ids-1)/7500);
run;
--
Paige Miller
Kiteulf
Quartz | Level 8

 

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 

 

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Patrick
Opal | Level 21

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 735 views
  • 0 likes
  • 3 in conversation