BookmarkSubscribeRSS Feed
Tobias_N
Calcite | Level 5

Hi,

I create charts with proc template and store them with proc document. Each graph has some text entered with

entry halign=left MyText /

valign=top

pad=(top=25px left=60px)


The replay has unespected results: All Charts have the same value for the variable "MyText". I started with a global macro variable (entry ... "&MyText." ...) and also tried defining MyText as MVAR or DYNAMIC variable in the proc template. The Charts are created correctly (I checked with ods html during the creation). Only the replay causes Problems in my code.

The code is attached and id be really happy for any help/clues to solve this problem. Thanks in advance.

Tobi


ods _all_ close;
title;footnote;

ods html;

quit;
ods document name=work.TestReport(write) cat=lib.TestReport;
ods document dir=(path=\Page1\Content1 );

%let MyText=(1) First graph.;
proc template;
  define statgraph MyTemp;
  dynamic MyText;
    begingraph;
   layout overlay;
   entry halign=left MyText /
    valign=top
    pad=(top=25px left=60px)
    ;
   barchart x=name y=age;
   endlayout;
    endgraph;
  end;
run;
proc sgrender
  data  = sashelp.class
  template = MyTemp
  ;
  dynamic MyText="&MyText.";
run;

ods document dir=(path=\Page1\Content2 );
%let MyText=(2) Different Text on the graph.;
proc template;
  define statgraph MyTemp;
    begingraph;
   layout overlay;
   entry halign=left "&MyText." /
    valign=top
    pad=(top=25px left=60px)
    ;
   barchart x=name y=age;
   endlayout;
    endgraph;
  end;
run;
proc sgrender
  data  = sashelp.class
  template = MyTemp
  ;
run;

ods document dir=(path=\Page1\Content3 );
%let MyText=(3) I dont get it.;
proc template;
  define statgraph MyTemp;
    begingraph;
   layout overlay;
   entry halign=left "&MyText." /
    valign=top
    pad=(top=25px left=60px)
    ;
   barchart x=name y=age;
   endlayout;
    endgraph;
  end;
run;
proc sgrender
  data  = sashelp.class
  template = MyTemp
  ;
run;

ods document close;
ods html close;

ods html;
proc document;
doc name=work.TestReport;
replay \Page1\Content3;
run;quit;
proc document;
doc name=work.TestReport;
replay \Page1\Content2;
run;quit;
proc document;
doc name=work.TestReport;
replay \Page1\Content1;
run;quit;

2 REPLIES 2
ballardw
Super User

Is there a reason for redefining the template at each step?

Leave the macro out of the template definition and call it with the SGRender


ods document name=work.TestReport(write) cat=lib.TestReport;
ods document dir=(path=\Page1\Content1 );


proc template;
  define statgraph MyTemp;
  dynamic MyText;
    begingraph;
   layout overlay;
   entry halign=left MyText /
    valign=top
    pad=(top=25px left=60px)
    ;
   barchart x=name y=age;
   endlayout;
    endgraph;
  end;
run;
%let mytext=(1) First graph.;
proc sgrender
  data  = sashelp.class
  template = MyTemp
  ;
  dynamic MyText="&mytext";
run;

ods document dir=(path=\Page1\Content2 );

%let mytext=(2) Second graph.;
proc sgrender
  data  = sashelp.class
  template = MyTemp ;
   dynamic MyText="&mytext";
;
run;

ods document dir=(path=\Page1\Content3 );

%let mytext= (3) I dont get it.;
proc sgrender
  data  = sashelp.class
  template = MyTemp  ;
  dynamic MyText="&mytext";
  ;
run;

ods document close;
ods html close;

ods html;


proc document;
doc name=work.TestReport;
replay \Page1\Content1;
run;
replay \Page1\Content2;
run;
replay \Page1\Content3;
run;
quit;

Tobias_N
Calcite | Level 5

Thanks for the answer: that works fine for the code I posted.

The reason I redefine the template is that I use different graphs and just reduced the problem here. I generate the templates on the fly (writing a MyTemplate.sas file and %include it) depending on the underlaying data. For some reason if you redefine a template that affects the proc replay although the graph is already created with sgrender. Solutions I tested are: different names for every generated template. Or trying to handle the dependance on data via dynamic variables (like the solution of ballardw). But both Solutions pose Problems to me:

In my actual template the appearance depends on the data e.g. the number of lines to draw or the axis tickvalues drawn with a loop. I use hash separated macro variables to create a loop.

%let var_names = DS_Variable_Name_1#DS_Variable_Name_2#DS_Variable_Name_3;

   %do i=&numVars. %to 1 %by -1;
    %let CurrentVar=%sysfunc(scan(&var_names,&i,#));
    %let CurrentLabel=%sysfunc(scan(&var_labels,&i,#));;
    %let legendStatement=&legendStatement. "i&i." ;

    %let CurrentColor=%sysfunc(scan(&SeriesColor.,&i,#));
    %let CurrentThickness=%sysfunc(scan(&SeriesThick.,&i,#));
    %let CurrentPattern=%sysfunc(scan(&SeriesPattern.,&i,#));

    seriesplot  x=SG_VN_VARFORMATNR y=&CurrentVar. /name="i&i."
                        display=(markers)
                        markerattrs=(symbol=&ChartSymbolCompari. color=&CurrentColor. weight=normal)
                        lineattrs=(color=&CurrentColor. thickness=&CurrentThickness. pattern=&CurrentPattern.)
                        legendlabel="&CurrentLabel" ;

   %end;

I did not manage to swich to "dynamic" template variables here because the scan function and Looping does not seem to work. Is there a way to extract values from delimiter seperated variables as template Input? or do I persue an unnecessary path?

I hope my Problem is well explained and thanks again for having a look.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1045 views
  • 3 likes
  • 2 in conversation