SAS - 将多个图形合并成一个pdf(空白页) [英] SAS - several graphs into one pdf (blank pages)

查看:632
本文介绍了SAS - 将多个图形合并成一个pdf(空白页)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题如下。我通过宏循环2图创建,我想将它们放到一个pdf页面中。在互联网上,我发现了这个解决方案,它可以正常工作,并创建一个页面和两个图形的PDF文档:

  ods _all_ close ; 
options papersize =ISO A4orientation = 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地区;
proc sgplot data = sashelp.class;
vbox age / group = sex;
跑;

ods地区;
proc sgplot data = sashelp.class;
直方图年龄;
跑;
ods layout end;
ods pdf close;

但是如果我为我的代码使用相同的逻辑,SAS会创建一个包含前两页的pdf文件空白,我的期望输出出现在第3页上。我的问题是为什么要添加两个空白页面以及如何纠正代码以消除它们。

  data out_i_a;设置sashelp.retail;跑; 
数据out_ii_b;设置sashelp.retail;跑;

data y;
长度saz tef $ 100;
输入saz $ tef $;
datalines;
i a
ii b
;
跑;

%macro grafy();
proc sql;
将count(*)选择为:y中的pocet;
退出;

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);
调用symput(saz,strip(saz));
调用symput(tef,strip(tef));
跑;

ods地区;
ods pdf text =& saz ._& tef;
symbol1 interpol =连接高度= 10pt VALUE = NONE LINE = 1 WIDTH = 1 CV = _STYLE_;
symbol2 interpol =连接高度= 10pt VALUE = NONE LINE = 1 WIDTH = 1 CV = _STYLE_;
Legend1值=('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;
跑;

ods地区;
symbol1 interpol =连接高度= 10pt VALUE = NONE LINE = 1 WIDTH = 1 CV = _STYLE_;
symbol2 interpol =连接高度= 10pt VALUE = NONE LINE = 1 WIDTH = 2 CV = _STYLE_;
Legend1值=('年''月');
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;
跑;
%end;

ods layout end;
ods pdf close;

%修正;

%grafy();

空白页的问题可以通过添加
$ b来解决$ b

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

放入代码中。

解决方案

我无法复制您的问题,但我强烈建议的一件事是使用SGPLOT而不是GPLOT。这是现代的,支持的图形选项。适合这种特殊的需求会容易得多。



举个例子:

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

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

ods地区;
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 =高度;
x2axis label =Weight;
yaxis label =年龄;
跑;

ods地区;
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 =高度;
x2axis label =Weight;
yaxis label =性别;
run; ods layout end;
ods pdf close;


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.

解决方案

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;

这篇关于SAS - 将多个图形合并成一个pdf(空白页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆