Dear SAS Community Member,
I have attached a preview of the data set I am going to ask you about. First, below is a brief description:
Data Description:
I actually have 5000 firm_ids, 49 industry names, myear goes up 200812.
My Goal:
My Progress:
*First impose the exclusion criterion via arrays;
data example ;
set example;
array industry(*) agric--chem;
do i=1 to dim(industry);
if input(vname(industry(i)) eq inames then call missing(industry(i)); *There seems to be an issue at this step. ;
end;
run;
%macro industry;
%do m=1 %to 2;
data reg&m ; set example; where id=&m; *create a separate data set for each id;
array industry(*) agric--chem; *introducing arrays in each data set, but I do not know how exactly I should do that;
do i=1 to dim(industry);
proc reg data=reg&m noprint outest=out tableout;
model returns =industry(i) ; *I want to store r-squared and others for each industry-id pair, but again I am not sure how to accomplish it;
data adjr t r; set out;
if _type_= 'adjrsq' then output adjr; .
if _type_='parms' then output p;
if _type_='t' then output t;
if _type_='rsq' then output r;
data &myoutput; set adjr p t r ; industry;
end; run;
proc append base=stats data=&myoutput; run;
%end;
%mend;
%industry;
I don't think you need ANY macros. If you get the data in the proper structure the entire analysis can be done with one call to PROC REG followed by a PROC SUMMARY to find the models(variables) of interest with max Rsquare.
Suggest you change the structure of Data firstly .then run REG by using BY statement.
%macro industry;
%do m=1 %to 2;
data reg&m ;
set example;
where id=&m; *create a separate data set for each id;
array industry(*) agric--chem; *introducing arrays in each data set, but I do not know how exactly I should do that;
do i=1 to dim(industry);
_industry=industry(i);
output;
end;
keep i _industry returns;
run;
proc sort data=reg&m ; by i ; run;
proc reg data=reg&m noprint outest=out tableout;
by i ;
model returns =_industry ; *I want to store r-squared and others for each industry-id pair, but again I am not sure how to accomplish it;
data adjr t r; set out;
if _type_= 'adjrsq' then output adjr; .
if _type_='parms' then output p;
if _type_='t' then output t;
if _type_='rsq' then output r;
data &myoutput; set adjr p t r ; industry;
end; run;
proc append base=stats data=&myoutput; run;
%end;
%mend;
Ksharp
I don't think you need ANY macros. If you get the data in the proper structure the entire analysis can be done with one call to PROC REG followed by a PROC SUMMARY to find the models(variables) of interest with max Rsquare.
Thank you Ksharp and data_null for your help. The second solution was a lot easier to implement than SAS macros. This is really a great community.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.