jiri jansa
jiri jansa

Reputation: 159

SAS - several graphs into one pdf (blank pages)

My problem is as follows. I create through macro loop 2 graphs and I would like to put them into one pdf page. On the internet I have found out this solution which works fine and creates pdf document with one page and two graphs:

ods _all_ close;
options papersize="ISO A4" orientation=portrait;
ods pdf file="C:\JJ\lapse_monitoring\lm201712_TEST\GRAF\sample.pdf";

ods graphics / width=12cm height=12cm;
ods layout gridded columns=1;

ods region;
proc sgplot data=sashelp.class;
vbox age / group=sex;
run;

ods region;
proc sgplot data=sashelp.class;
histogram age;
run;
ods layout end;
ods pdf close;

But if I use the same logic for my code, SAS creates one pdf file with the first two pages blank and my desired output comes on the 3rd page. My question is why there are two blank pages added and how to correct the code to get rid of them.

data out_i_a; set sashelp.retail; run;
data out_ii_b; set sashelp.retail; run; 

data y;
length saz tef $100;
input saz $ tef $; 
datalines;
i a
ii b
;
run;

%macro grafy();
proc sql;
  select count(*) into: pocet from y;
quit;

ods _all_ close;
/*goptions reset=all hsize=22cm vsize=10cm;*/
ods pdf file="C:\TOT_test.pdf";
ods layout gridded columns=1;


%do i=1 %to &pocet;
data _null_;
   set y (obs=&i);
   call symput("saz" ,strip(saz));
   call symput("tef" ,strip(tef));
run;

ods region;
ods pdf text="&saz._&tef";
symbol1 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
symbol2 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
Legend1 value=('SALES' 'YEAR');
axis1 label=('# sales');
axis3 label=('# year');
axis2 label=('date');
proc gplot data= out_&saz._&tef;
plot (SALES)*DATE   / overlay skipmiss
VAXIS=AXIS1 
HAXIS=AXIS2 LEGEND=Legend1;
plot2 (YEAR)*DATE / overlay skipmiss
VAXIS=AXIS3
HAXIS=AXIS2 LEGEND=Legend1;
run;

ods region;
symbol1 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=1 CV= _STYLE_;
symbol2 interpol=join height=10pt VALUE=NONE LINE=1 WIDTH=2 CV= _STYLE_;
Legend1 value=('year' 'month');
axis1 label=('in %, p.a.');
axis2 label=('date');
proc gplot data= out_&saz._&tef;
 plot (YEAR MONTH)*DATE   / overlay skipmiss
 VAXIS=AXIS1 
 HAXIS=AXIS2 LEGEND=Legend1;
run;
 %end;

ods layout end;
ods pdf close;

%mend;

%grafy();

The issue with the blank pages can be solved by adding

goptions reset=all hsize=22cm vsize=10cm; 

into the code.

Upvotes: 0

Views: 1189

Answers (1)

Joe
Joe

Reputation: 63424

I can't replicate your issue, but one thing I strongly suggest is to use SGPLOT instead of GPLOT. It's the modern, supported graphing option. It will be much easier to make fit into this particular need.

For an example:

ods _all_ close;
options papersize="ISO A4" orientation=portrait;
ods pdf file="C:\temp\sample.pdf";

ods graphics / width=12cm height=12cm;
ods layout gridded columns=1;

ods region;
proc sgplot data=sashelp.class;
scatter x=weight y=age/x2axis markercharattrs=(color=blue)  markerfillattrs=(color=blue) markerattrs=(symbol=circlefilled); 
scatter x=height y=age/ markercharattrs=(color=red) markerfillattrs=(color=red) markerattrs=(symbol=diamondfilled);
xaxis label="Height";
x2axis label="Weight";
yaxis label="Age";
run;

ods region;
proc sgplot data=sashelp.class;
scatter x=weight y=sex/x2axis markercharattrs=(color=blue) filledoutlinedmarkers markerfillattrs=(color=blue) markerattrs=(symbol=circlefilled); 
scatter x=height y=sex/ markercharattrs=(color=red) filledoutlinedmarkers markerfillattrs=(color=red) markerattrs=(symbol=diamondfilled);
xaxis label="Height";
x2axis label="Weight";
yaxis label="Sex";
run;ods layout end;
ods pdf close;

Upvotes: 1

Related Questions