<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Question about using macro to generate several similar cells in PROC TEMPLATE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633942#M188121</link>
    <description>Great! The code solves my problems totally!&lt;BR /&gt;Thanks for your perfect solution!&lt;BR /&gt;Like!</description>
    <pubDate>Sun, 22 Mar 2020 14:12:19 GMT</pubDate>
    <dc:creator>myrenO3</dc:creator>
    <dc:date>2020-03-22T14:12:19Z</dc:date>
    <item>
      <title>Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633923#M188114</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;recently i wanna to draw a lattice layout plot where lots of sub-plots (cells) are avaliable. such as code like that..:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
	define statgraph myren_density;
		begingraph;
		entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
			"Table 1: Distributions of metals log-transformed concentraions";
		entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
			weight=normal color=CX8470FF) "Note: made by Myren";
		layout lattice / columns=1;&lt;BR /&gt;
		/*Hg*/
		&lt;FONT color="#FF0000"&gt;cell;&lt;/FONT&gt;
		  cellheader;
		    layout gridded;
		    entry "Hg";
		    endlayout;
		  endcellheader;
		  layout overlay;
		    histogram eval(log(&lt;FONT color="#FF0000"&gt;Hg&lt;/FONT&gt;));
		    densityplot eval(log(&lt;FONT color="#FF0000"&gt;Hg&lt;/FONT&gt;));
		   endlayout;
		&lt;FONT color="#FF0000"&gt;endcell;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;/*Here I want to add several similar cell blocks like cell "Hg" where only variable "Hg" will be changed by other variable name ("Cd"”As“ for example)*/&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;
		sidebar / align=bottom;
		entry "Log-transformed Concentration(μg/g)" / textattrs=(family="Times New Roman" 
			size=12 weight=normal) pad=(left=30);
		endsidebar;
		endlayout;
		endgraph;
	end;
run;

proc sgrender data=df template=myren_density;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use CALL EXECUTE but failed. It seemed that the CALL EXECUTE routines resolved the codes inside them seperately when SAS finished compiling?&lt;/P&gt;&lt;P&gt;But i hoped&amp;nbsp; that the produced codes can "be generated together" and "run simultaneously". Obviously&amp;nbsp; the code below can't.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone suggestions or better solutions&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA  VARLIST;&lt;FONT color="#FF0000"&gt;/*Var list*/&lt;/FONT&gt;
    INPUT  VAR $8.;
DATALINES;
Hg
Cd
Cr
As
Pb
...
;
RUN;&lt;BR /&gt;&lt;BR /&gt;%MACRO CELLS(VAR);&lt;FONT color="#FF0000"&gt;/*macro that generating cells*/&lt;/FONT&gt;&lt;BR /&gt;		&lt;FONT color="#000000"&gt;cell;
		  cellheader;
		    layout gridded;
		    entry "Hg";
		    endlayout;
		  endcellheader;
		  layout overlay;
		    histogram eval(log(&amp;amp;VAR.));
		    densityplot eval(log(&amp;amp;VAR.));
		   endlayout;
		endcell;&lt;BR /&gt;&lt;/FONT&gt;%MEND&amp;nbsp;CELLS;&lt;BR /&gt;&lt;BR /&gt;DATA&amp;nbsp;_NULL_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;SET&amp;nbsp;VARLIST;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;IF&amp;nbsp;_N_=1&amp;nbsp;THEN&amp;nbsp;CALL&amp;nbsp;EXECUTE('%NRSTR(proc template;
	define statgraph myren_density;
		begingraph;
		entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
			"Table 1: Distributions of metals log-transformed concentraions";
		entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
			weight=normal color=CX8470FF) "Note: made by Myren";
		layout lattice / columns=1;)');&lt;FONT color="#FF0000"&gt;/*Beiginning part of proc templete*/&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&amp;nbsp;CALL&amp;nbsp;EXECUTE('%NRSTR(%CELLS('||VAR||'))');&lt;FONT color="#FF0000"&gt;/*Generate multiple cells*/&lt;BR /&gt;&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;IF&amp;nbsp;LAST.&amp;nbsp;THEN&amp;nbsp;CALL&amp;nbsp;EXECUTE('%NRSTR(sidebar / align=bottom;
		entry "Log-transformed Concentration(μg/g)" / textattrs=(family="Times New Roman" 
			size=12 weight=normal) pad=(left=30);
		endsidebar;
		endlayout;
		endgraph;
	end;
run;
proc sgrender data=df template=myren_density;
run;)');&lt;FONT color="#FF0000"&gt;/*End part of proc templete as well as proc sgrender*/&lt;BR /&gt;&lt;/FONT&gt;&lt;BR /&gt;RUN;&lt;FONT color="#FF0000"&gt;/*DATA SETP END*/&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 08:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633923#M188114</guid>
      <dc:creator>myrenO3</dc:creator>
      <dc:date>2020-03-22T08:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633924#M188115</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cell(var);
		cell;
		  cellheader;
		    layout gridded;
		    entry "&amp;amp;var";
		    endlayout;
		  endcellheader;
		  layout overlay;
		    histogram eval(log(&amp;amp;var));
		    densityplot eval(log(&amp;amp;var));
		   endlayout;
		endcell;
%mend;

proc template;
	define statgraph myren_density;
		begingraph;
		entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
			"Table 1: Distributions of metals log-transformed concentraions";
		entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
			weight=normal color=CX8470FF) "Note: made by Myren";
		layout lattice / columns=1;
 %cell(Hg)
 %cell(Cd)
		sidebar / align=bottom;
		entry "Log-transformed Concentration(μg/g)" / textattrs=(family="Times New Roman" 
			size=12 weight=normal) pad=(left=30);
		endsidebar;
		endlayout;
		endgraph;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 09:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633924#M188115</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-22T09:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633925#M188116</link>
      <description>&lt;P&gt;Storing the cell names in a macro variable and then looping over it should do the trick.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data varlist;
  input  var $8.;
  datalines;
hg
cd
cr
as
pb
;

%let varlist=;
proc sql noprint;
  select var into :varlist separated by ' ' 
  from varlist
  ;
quit;

%macro cells(var);
  %do i=1 %to %sysfunc(countw(&amp;amp;var));
    %let thisVar=%scan(&amp;amp;var.,&amp;amp;i);
    cell;
      cellheader;
        layout gridded;
        entry "&amp;amp;thisVar";
        endlayout;
      endcellheader;
      layout overlay;
      histogram eval(log(&amp;amp;thisVar));
      densityplot eval(log(&amp;amp;thisVar));
      endlayout;
    endcell;
  %end;
%mend cells;

proc template;
  define statgraph myren_density;
    begingraph;
    entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
      "Table 1: Distributions of metals log-transformed concentraions";
    entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
      weight=normal color=CX8470FF) "Note: made by Myren";
    layout lattice / columns=1;
    %cells(&amp;amp;varlist)
    sidebar / align=bottom;
    entry "Log-transformed Concentration(µg/g)" / textattrs=(family="Times New Roman" 
      size=12 weight=normal) pad=(left=30);
    endsidebar;
    endlayout;
    endgraph;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 09:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633925#M188116</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-22T09:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633940#M188119</link>
      <description>&lt;P&gt;Yeah, thanks for your reminding. it does really work. But if we have lots of cells to be generated (fifty for example?), perhaps the code would be&amp;nbsp; a little complex?&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2020 13:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633940#M188119</guid>
      <dc:creator>myrenO3</dc:creator>
      <dc:date>2020-03-22T13:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633941#M188120</link>
      <description>&lt;P&gt;It should be possible with CALL EXECUTE. Are you sure the code you are generating will work? Did you try an example first to make sure? If it CAN work then just check the log to see if the lines of code your data step generated match what you want. They are easy to see in the log since they will have + at the start of the line.&lt;BR /&gt;&lt;BR /&gt;It is probably going to be easier debug the code generation if you use the data step just write the series of macro calls to a temporary text file (use PUT statement). Then to run it you just have the beginning and ending statements of the PROC TEMPLATE code in your program and use %INCLUDE to call in the macro calls from the temporary file at the place where you need them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for macro or macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set varlist ;
  file code ;
  put 'cell;'
    / '  cellheader;'
    / '    layout gridded;'
    / '      entry ' var :$quote. ';'
    / '    endlayout;'
    / '  endcellheader;'
    / '  layout overlay;'
    / '    histogram eval(log(' var '));'
    / '    densityplot eval(log(' var '));'
    / '  endlayout;'
    / 'endcell;'
  ;
run;

proc template;
  define statgraph myren_density;
    begingraph;
    entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
      "Table 1: Distributions of metals log-transformed concentraions";
    entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
      weight=normal color=CX8470FF) "Note: made by Myren";
    layout lattice / columns=1;
 %include code / source2;
    sidebar / align=bottom;
    entry "Log-transformed Concentration(µg/g)" / textattrs=(family="Times New Roman" 
      size=12 weight=normal) pad=(left=30);
    endsidebar;
    endlayout;
    endgraph;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Mar 2020 14:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633941#M188120</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-22T14:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633942#M188121</link>
      <description>Great! The code solves my problems totally!&lt;BR /&gt;Thanks for your perfect solution!&lt;BR /&gt;Like!</description>
      <pubDate>Sun, 22 Mar 2020 14:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633942#M188121</guid>
      <dc:creator>myrenO3</dc:creator>
      <dc:date>2020-03-22T14:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633944#M188123</link>
      <description>Thanks for your suggestion! Good idea&lt;BR /&gt;Putting the macro calls to a temporary file and using %INCLUDE haalso sound cool. I' ll have a try later.</description>
      <pubDate>Sun, 22 Mar 2020 14:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633944#M188123</guid>
      <dc:creator>myrenO3</dc:creator>
      <dc:date>2020-03-22T14:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Question about using macro to generate several similar cells in PROC TEMPLATE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633987#M188135</link>
      <description>&lt;P&gt;And if you don't have a lot of variable names then you can of course pass in the names also directly as a blank list in a single or multiple calls to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
  define statgraph myren_density;
    begingraph;
    entrytitle textattrs=(size=12 family="Times New Roman" weight=bold) 
      "Table 1: Distributions of metals log-transformed concentraions";
    entryfootnote halign=left textattrs=(size=9 family="Times New Roman" 
      weight=normal color=CX8470FF) "Note: made by Myren";
    layout lattice / columns=1;
    %cells(hg cd cr as)
    %cells(pb)
    sidebar / align=bottom;
    entry "Log-transformed Concentration(µg/g)" / textattrs=(family="Times New Roman" 
      size=12 weight=normal) pad=(left=30);
    endsidebar;
    endlayout;
    endgraph;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Mar 2020 20:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-using-macro-to-generate-several-similar-cells-in/m-p/633987#M188135</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-22T20:18:19Z</dc:date>
    </item>
  </channel>
</rss>

