0

I am trying to parse values from data step to gplot procedure to add some statistic to graphs using call symput function. but it seems that only the last observation has been passed to gplot. how can I fix this problem? Thanks.

libname out "c:\sas output";
%global ID;
%global RSQ;
%global RMSE; 

%macro plot(in=,id=);
    axis1;
    axis2 label=(angle=90 justify=center);
    symbol1 value=dot c=bib h=15pt i=rl;
    symbol2 value=dot c=red h=15pt i=rl;
    legend1 position=(outside center bottom) frame label=("Blade ID" font=arial height=15pt) ;
    proc gplot data=∈
        title1 "Correlation of &id &RSQ &RMSE";
        plot ser*ttmcw_nm/ grid legend=legend1 haxis=axis1 vaxis=axis2 annotate=reg;
        where Blade_ID="&id";
    run;
%mend;

data _null_;
    set reg;
    call symput('ID',Blade_ID);
    call symput('RSQ',_RSQ_);
    call symput('RMSE',_RMSE_);
    %put &ID;
    %plot(in=out.bladeraw,id=&ID);
run;

enter image description here enter image description here

Samuel
  • 49
  • 5

1 Answers1

1
  1. Regarding your code

Note: Here is SAS documentation (Chapters 2,4) about how SAS code is processed step by step.

Lines beginning with%put and %plot are resolved by macro processor only once, independently from data step loop. To print all &ID. values to log you can use

par = symget('ID');
put par;

instead. To run %plot in a loop you can put it in a macro-language loop, see point 2.

  1. Proposed code reconstruction

    %macro generate_plots();

    %let vars=;
    proc sql noprint;
        select Blade_ID into :vars separated by '#' from reg;
    quit;
    %put &vars.;
    
    %let i = 1;
    %let var = %scan(%BQUOTE(&vars.), &i., %BQUOTE(#));
    %do %while(&var. ne);
        %plot(in=out.bladeraw, id=&var.);
        %let i = %eval(&i. + 1);
        %let var = %scan(%BQUOTE(&vars.), &i., %BQUOTE(#));
        %put &var.;
    %end;
    

    %mend; %generate_plots();

hanna
  • 627
  • 9
  • 15