【问题标题】:SAS: PROC SGPLOT BY GROUP auto file namesSAS:PROC SGPLOT BY GROUP 自动文件名
【发布时间】:2012-02-28 16:28:17
【问题描述】:

我正在使用 BY GROUP 选项绘制一些数据。虽然我可以使用#byval 选项自动将 BY GROUP 值放在每个图的标题中,但我想单独保存每个图并希望在 #byval 之后命名它而不是调用它 - SGPLOT01、SGPLOT02 ...

例如假设我有:

data xyz;
input type$ x y1 y2@@;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;

PROC SGPLOT DATA=xyz;
by type;
series1 x=x y=y1/markers;
series2 x=x y=y2/markers;
title "#byval";
RUN;

在本例中,将为类型 A 和 B 分别创建两个图。但程序会自动将它们命名为 SGPLOT1.pdf 和 SGPLOT2.pdf。我宁愿将它们命名为 A.pdf 和 B.pdf,并希望将它们保存到目录“C:/SGPLOTS/”。

感谢您的帮助。

【问题讨论】:

    标签: plot sas sas-ods


    【解决方案1】:

    一种选择是使用 ODS 并使用宏分别打印每个 TYPE,如下例所示。

    data xyz;
    input type$ x y1 y2 @@;
    cards;
    A 1 5 7
    A 2 7 9
    A 3 8 10
    B 1 5 7
    B 2 7 9
    B 3 8 10
    ;
    RUN;
    
    ods listing close;
    
    %macro plot_it(type=);
    
       goptions reset
          device = sasprtc
          target = sasprtc
          ;
    
       ods pdf file="C:/SGPLOTS/&type..pdf" notoc;
    
       PROC SGPLOT DATA=xyz;
       by type;
       where type = "&type";
       series x=x y=y1/markers;
       series x=x y=y2/markers;
       title "#byval";
       RUN;
    
       ods pdf close;
    
    %mend plot_it;
    
    %plot_it(type=A);
    %plot_it(type=B);
    

    【讨论】:

    • ... 如果类型很多,您可以使用call execute 替换硬编码的宏调用。
    【解决方案2】:

    您想在#BYVAL 之后的括号内添加变量名称。在此示例中,您希望将 #byval(type) 放在您的标题中。

    我已将您的示例放入 SAS 称为“HTML 三明治”的东西中,即顶部两行,底部两行。此外,我添加了 helpbrowser 选项,它告诉 SAS 使用自己的功能来显示 html 输出。

    option helpbrowser=sas;
    
    /**** top of html sandwich *****/
    ods html ;
    ods graphics on; 
    /*******************************/
    
    
    data xyz;
    input type$ x y1 y2@@;
    cards;
    A 1 5 7
    A 2 7 9
    A 3 8 10
    B 1 5 7
    B 2 7 9
    B 3 8 10
    ;;
    RUN;
    
    PROC SGPLOT DATA=xyz;
    by type;
    series x=x y=y1/markers;
    series x=x y=y2/markers;
    title "Here is the type:  #byval(type)";
    RUN;
    
    
    /**** bottom of html sandwich *****/
    ods graphics off;
    ods html close;
    /**********************************/
    

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多