Создать PDF-файл всех линейчатых графиков, добавленных вместе

Я создал серию графиков, используя proc gbarline, и я хочу экспортировать все графики в один PDF, а не только первый график, у меня две проблемы:

  1. график не экспортируется в pdf, если я не напечатал первый график дважды, поэтому я использую оператор

    %if &index. = 1 %then %do;
    <statements>;
    %end;
    
  2. PDF содержит только первый сюжет

Код, который я использую ниже:

%macro test_pdf;

    data snp (drop=i);
        do i = 1 to 100;
            y = ranuni(0);
            x1 = ranuni(0) * 5;
            x2 = ranuni(0) * 10;
            x3 = ranuni(0) * 7;
            x4 = ranuni(0) * 4;
            x5 = ranuni(0) * 100;
            x6 = ranuni(0) * 50;
            x7 = ranuni(0) * 1000;
            x8 = ranuni(0) * 10000;
            x9 = ranuni(0) * 9999;
            x10 = ranuni(0) * 5984;
            x11 = ranuni(10) * 5;
            x12 = ranuni(10) * 10;
            x13 = ranuni(10) * 7;
            x14 = ranuni(10) * 4;
            x15 = ranuni(10) * 100;
            x16 = ranuni(10) * 50;
            x17 = ranuni(10) * 1000;
            x18 = ranuni(10) * 10000;
            x19 = ranuni(10) * 9999;
            x20 = ranuni(10) * 5984;
            x21 = ranuni(20) * 5;
            x22 = ranuni(20) * 10;
            x23 = ranuni(20) * 7;
            x24 = ranuni(20) * 4;
            x25 = ranuni(20) * 100;
            x26 = ranuni(20) * 50;
            x27 = ranuni(20) * 1000;
            x28 = ranuni(20) * 10000;
            x29 = ranuni(20) * 9999;
            x30 = ranuni(20) * 5984;
            x31 = ranuni(30) * 5;
            x32 = ranuni(30) * 10;
            x33 = ranuni(30) * 7;
            x34 = ranuni(30) * 4;
            x35 = ranuni(30) * 100;
            x36 = ranuni(30) * 50;
            x37 = ranuni(30) * 1000;
            x38 = ranuni(30) * 10000;
            x39 = ranuni(30) * 9999;
            x40 = ranuni(30) * 5984;
            output;
        end;
    run;

    PROC CONTENTS DATA = snp OUT = snp_contents NOPRINT;
    RUN;

    PROC SQL NOPRINT;
        SELECT name INTO: snp_factors 
            separated by " " 
        FROM snp_contents
            WHERE varnum > 1;
        SELECT name INTO: snp_response
            FROM snp_contents
                WHERE varnum = 1;
        SELECT max(length(name)) INTO: max_length
            FROM snp_contents;
    QUIT;

    ODS HTML CLOSE;
    ODS HTML;
    QUIT;

    %LET timestamp = %sysfunc(putn(%sysfunc(date()),yymmddn8.));
    %LET hourstamp = %sysfunc(compress(%sysfunc(TIME(),time.),%str( :)));
    ODS TRACE ON;
    ODS PDF FILE = "&ROOT\output_data\_&timestamp._&hourstamp._Histogram_gbarline.pdf";
    ODS SELECT gbarlin;
    %LET index = 1;

    %DO %UNTIL (%SCAN(&snp_factors.,&index.," ")=);
        %LET factors = %SCAN(&snp_factors.,&index.," ");

        %IF &index. = 1 %THEN
            %DO;

                PROC GBARLINE DATA=snp
                ;
                    BAR  &factors.
                        /
                        FRAME LEVELS=10
                        TYPE=PCT
                        MISSING
                        COUTLINE=BLACK
                    ;
                    PLOT / SUMVAR=&snp_response.
                        TYPE=MEAN
                    ;
                RUN;

                QUIT;

            %END;

        PROC GBARLINE DATA=snp
        ;
            BAR  &factors.
                /
                FRAME LEVELS=10
                TYPE=PCT
                MISSING
                COUTLINE=BLACK
            ;
            PLOT / SUMVAR=&snp_response.
                TYPE=MEAN
            ;
        RUN;

        QUIT;

        ODS PDF CLOSE;
        %LET index = %EVAL(&Index + 1);
    %END;
%mend;

%test_pdf;

1 ответ

Решение

You are closing the PDF inside the %DO %UNTIL петля.

+ Изменить

    … 
    ODS PDF CLOSE;
    %LET index = %EVAL(&Index + 1);
%END;

в

    … 
    %LET index = %EVAL(&Index + 1);
%END;
ODS PDF CLOSE;

Because you closed inside the loop, only the first iteration was in the PDF output. The subsequent ODS PDF CLOSE statements inside the loop were accepted by SAS and discarded silently (no log messages) because the PDF destination was already closed.

Другие вопросы по тегам