I made an executable example that can produce a pdf result to hopefully get across what I want to achieve. You only need to change the path definition in the following code and it should run fine. This code runs 3 regressions, for each regression, 3 pages of outputs are saved. What I want is a code (the simple the better) that can generate 3 separate pdf files, with: File number 1 combining page 1,4,7 of the product of this code; This is all the regression outcome. File number 2 combining page 2,5,8 of the product of this code; This is all the key statistics. File number 3 combining page 3,6,9 of the product of this code; This is all the plots. data raw;
set sashelp.cars;
keep msrp invoice enginesize horsepower;
run;
proc contents data=raw out=cont;run;
proc sql;
create table count as
select count(distinct name) as varcount
from cont
where lower(name)^="invoice"
;
quit;
data _null_;set count;call symputx ('count', varcount); run;
%put &count;
data varlist;set cont (where=(lower(name)^="invoice"));_num+1;run;
/*define pdf path here*/
%let path = ...;
%macro work;
ods pdf file="&path./allout.pdf";
%do i=1 %to %eval(&count.);
data _null_;set varlist;where _num=&i.;call symputx('var',name);run;
%put &var.;
/*task 1, records regression outcome*/
ods output FitStatistics = fitstats;
proc reg data=raw outest=param tableout;
model invoice=&var. ;
output out=reg_out p=predicted r=residual /*residual is actual - predicted values*/;
run;
/*task 2, gather model stats and output*/
data stats1;
set param;
where _TYPE_="PARMS";
keep &var. ;
rename &var.=Estimate;
run;
data stats2;
set param;
where _TYPE_="PVALUE";
if &var.<=0.1 then Sig_flag=1; else Sig_flag=0;
keep &var. Sig_flag;
rename &var.=P_value;
run;
data stats3;
set fitstats;
where label2="R-Square";
keep nvalue2;
rename nvalue2=R_squared;
run;
data stats4;
set fitstats;
where label2="Adj R-Sq";
keep nvalue2;
rename nvalue2=Adj_Rsquared;
run;
data stats_merge;
retain iter Variable Estimate Sig_flag P_value R_squared Adj_Rsquared;
merge stats1 stats2 stats3 stats4;
iter=&i.;
Variable="&var.";
run;
proc print data=stats_merge;run;
/*task 3, plot observed and predcited values*/
proc gplot data=reg_out;
plot invoice*&var. predicted*&var. / overlay;
run;
%end;
ods pdf close;
%mend work;
%work;
... View more