macros - SAS Regression by class variable -


i wish perform multiple regressions conditionally based on value of categorical variable. so, simple example, consider sashelp.class data. need perform regression males , females. since dataset has many more divisions , larger, start feeding different types macro variables:

proc sql;     select count(distinct sex) :numsex     sashelp.class;     %let numsex=&numsex;     select distinct sex :sex1 - :sex&numsex     sashelp.class; quit; 

then trying perform regression on each 1 looping them through. know commented out code works, unsure why macro function not working.

/**/ /*data dataf;*/ /*  set sashelp.class;*/ /*  sex='f';*/ /*run;*/ /**/ /*proc reg data=dataf outest=out1;*/ /*  model height=weight;*/ /*run;*/  %macro regress; %do = 1 %to &numsex;  data data&&sex&i;     set sashelp.class;     sex='&&sex&i'; run;  proc reg data=data&&sex&i outest=out&i;     model height=weight; run; %end; %mend; %regress; 

also, if there better way this, i'm ears. current way pain since have combine of output sets of estimates 1 dataset. also, bunch of intermediate datasets don't want or need.

thanks.

usually group best way this, not sure if you're looking for:

proc sort data=sashelp.class out=class; sex; run;  proc reg data=class outest=out1;   sex;   model height=weight; run; 

your macro failed because single quotes stop macro variable resolution (ie, '&sex' not work 'f'; have use "&sex" "f".)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -