Hey guys,
even though there are some very helpful ressources on ods layout, which I used in the past, I do not manage to implement the ods layout/ods region statement successfully in my code. My example code is a slightly modified version of a code that @Oligolas helped me out with (https://communities.sas.com/t5/SAS-Programming/Using-conditional-logic-to-join-tables-inside-a-do-loop/m-p/886086#M350159). The desired result should look similar to the Screenshots down below. To summarize my question: How can I incorporate ODS layout within my do-loop to display two (or more) PROC REPORT tables side by side, instead of stacking them vertically?
proc datasets lib=work kill nolist;run;quit;
%let yourpath=C:\;
/*** Example Data ***/
data work.sample_data;
input EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;
datalines;
10 20 30 40 50 1 2 3 2 3
15 25 35 45 55 1 3 4 3 2
5 10 15 20 25 2 2 3 3 2
20 30 40 50 60 4 3 2 1 1
25 35 45 55 65 1 1 1 2 3
;
run;
data work.input_data;
length Info1 $9 Info2 $16;
input Info1 $ Info2 $ Sort;
infile datalines delimiter=",";
datalines;
Variable,Answer your Item,1
AGHK50A,Item A,1
AGHK50B,Item B,1
AGHK50C,Item C,1
Variable,Answer your Item,2
BGKO28A,Item A,2
BGKO28B,Item B,2
Variable,Answer your Item,3
EZGH25A,Item A,3
EZGH25B,Item B,3
EZGH25C,Item C,3
EZGH25D,Item D,3
EZGH25E,Item E,3
;
/* Using proc sql for a Sorting Variable which is used to iterate trough the do-loop */
proc sql noprint;
select distinct Sort into :Sort separated by " "
from work.input_data;
quit;
%put &Sort;
%let varlistE = EZGH25A EZGH25B EZGH25C EZGH25D EZGH25E;
%let varlistA = AGHK50A AGHK50B AGHK50C BGKO28A BGKO28B;
/* Mean Calculation */
proc means data=work.sample_data noprint;
var &varlistE;
output out=work.mean_ezgh;
run;
%macro meandata;
%do i = 1 %to %sysfunc(countw(&varlistE));
%let vmean = %scan(&varlistE, &i);
data work.mean&vmean;
set work.mean_ezgh (keep=&vmean);
run;
%end;
%mend meandata;
%meandata;
/* Freq calculation */
%macro freqdata;
%do i = 1 %to %sysfunc(countw(&varlistA));
%let vfreq = %scan(&varlista, &i);
proc freq data=work.sample_data;
tables &vfreq/ out=work.freq&vfreq;
run;
%end;
%mend freqdata;
%freqdata;
/*** Macro Loop ***/
ods _all_ close;
options leftmargin=.001in rightmargin=.001in topmargin=.001in bottommargin=.001in nodate nonumber;
%macro Testloop;
%do i = 1 %to %sysfunc(countw(&Sort.));
%let SortID = %scan(&sort, &i);
%let VariableA = %scan(&varlistA, &i);
%let VariableE = %scan(&varlistE, &i);
ods pdf file="&yourpath.\LoopTest.pdf";
ods pdf startpage=now;
ods layout start width=19cm height=27cm;
/* Compute Variable Information for each Variable */
data VariableInfo;
set work.input_data;
where Sort = &SortID.;
drop Sort;
run;
%local Info1Items;
%let Info1Items=;
PROC SQL noprint;
SELECT distinct Info1 INTO :Info1Items SEPARATED BY " "/*new*/
FROM work.input_data
WHERE Sort = &SortID.
AND Info1 not in ('' 'Variable');
QUIT;
/* Report Variable Information for each Variable */
proc report data=VariableInfo noheader;
column Info1 Info2;
run;
ods layout end;
%MACRO PrinItemStats(Item=);
%if %sysfunc(exist(freq&Item.)) %then %do;
/* Print Frequency Table */
ods layout gridded advance=proc columns=2;
proc report data=freq&Item.;
column &Item. COUNT PERCENT;
define &Item / display "&Item.";
define COUNT / display "Absolut";
define PERCENT / display "Percent";
run;
ods layout end;
%end;
%if %sysfunc(exist(mean&Item.)) %then %do;
/* Print Mean Table */
ods layout gridded advance=proc columns=2;
proc report data=mean&Item.;
column &Item.;
run;
ods layout end;
%end;
%MEND PrinItemStats;
%local j currItem;
%LET j=1;
%LET currItem=%SCAN(&Info1Items.,&j.,%STR( ));
%DO %WHILE(%LENGTH(&currItem.)>0);
%PrinItemStats(Item=&currItem.);
%LET j=%EVAL(&j.+1);
%LET currItem=%SCAN(&Info1Items.,&j.,%STR( ));
%END;
%end;
ods pdf close;
%mend Testloop;
%Testloop;
... View more