<?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: proc sgplots of multiple variables in macro do loop - but only first variable is graphed in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803601#M316435</link>
    <description>Thanks Paige - I tried rerunning with the statement:&lt;BR /&gt;&lt;BR /&gt;ods html file="scatterplot_&amp;amp;i.html" path='.' style=styles.statistical;&lt;BR /&gt;&lt;BR /&gt;but I'm still getting duplicate graphs.</description>
    <pubDate>Wed, 23 Mar 2022 16:48:09 GMT</pubDate>
    <dc:creator>RobertWF1</dc:creator>
    <dc:date>2022-03-23T16:48:09Z</dc:date>
    <item>
      <title>proc sgplots of multiple variables in macro do loop - but only first variable is graphed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803584#M316423</link>
      <description>&lt;P&gt;I'm attempting to automate graphing of outcome variable mean values &amp;amp; error bars by embedding proc sgplot inside a macro do loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately my code is only plotting the first variable over and over when it loops rather than plotting all 28 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a sample of my code &amp;amp; data for 2 variables that replicates the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thoughts what I'm doing wrong?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data macrovars3;
input trmt $ prez1	prez2	postz1	postz2;
cards;
No 0 1 0 0
No 1 1 0 1
No 1 0 1 0
No 1 0 1 0
No 0 0 0 0
No 0 0 0 0
No 0 0 0 0
No 0 0 0 0
No 0 0 0 0
Y 1 0 1 0
Y 1 1 1 0
Y 1 1 0 1
Y 1 1 1 1
Y 0 0 0 0
Y 0 0 1 0
Y 1 0 0 0
Y 1 1 0 1
Y 1 1 0 1
Y 1 0 1 0
Y 1 0 1 0
;
run;

/* Macro variables for medical diagnosis categories */
%let z1 = CHF;
%let z2 = VALVE;

/* Macro graphing loop */
%macro RunPlot(DSName, NumVars);
%do i=1 %to &amp;amp;NumVars; 
	/* Stack datasets for pre and post outcomes and diagnosis, create period indicator. */
	data cohort_match_real_data_ge0_pre (keep=trmt period diagnosis);
	set &amp;amp;DSName; 
		length period $4.;
		period = "Pre";
		diagnosis = prez&amp;amp;i;
	run;
	data cohort_match_real_data_ge0_post (keep=trmt period diagnosis);
	set &amp;amp;DSName; 
		length period $4.;
		period = "Post";
		diagnosis = postz&amp;amp;i;
	run;
	data cohort_match_prepost;
	set cohort_match_real_data_ge0_pre cohort_match_real_data_ge0_post; 
	run;

	/* Calculate the means and the standard errors. */ 
	proc sort data=cohort_match_prepost out=cohort_match_prepost_2;
		by trmt period;
	run; 
	 
	ods trace on;                                                                                                                     
	proc means data=cohort_match_prepost_2;                                                                                                      
		by trmt period;                                                                                                                            
	   	var diagnosis;                                                                                                                            
	   	ods output summary=meansout;                                                                                         
	run;  
	                                                                                                                                        
	/* Calculate the upper and lower error bar values. */                                                                                       
	data meansout;                                                                                                                
	set meansout;                                                                                                                        
	   lowerCI_diagnosis = diagnosis_Mean - 1.96*diagnosis_StdDev/diagnosis_N**.5;                                                                                                                 
	   upperCI_diagnosis = diagnosis_Mean + 1.96*diagnosis_StdDev/diagnosis_N**.5;  
	run;   

	/* Plot mean values of pre and post diagnoses */
	ods listing close;                                                                                                                      
	ods html file='scatterplot.html' path='.' style=styles.statistical;                                                                     
	ods graphics / reset attrpriority=color width=600px height=400px imagefmt=gif;                                                                                                                                                                                                                                                                
	proc sgplot data=meansout;  
	   	scatter x=period y=diagnosis_Mean / group=trmt 
			yerrorlower=lowerCI_diagnosis                                                                                          
			yerrorupper=upperCI_diagnosis                                                                                            
	        markerattrs=(symbol=CircleFilled);                                                              
	   	series x=period y=diagnosis_Mean / group=trmt lineattrs=(thickness=2);  
		yaxis grid gridattrs=(color=white); 
		xaxis grid gridattrs=(color=white pattern=shortdash) offsetmin=0.2 offsetmax=0.2; 
		styleattrs backcolor=CXFFFFFF wallcolor=CXE0E0E0;
	/*	keylegend "pre" "post";*/
	   	title1 "Plot pre_&amp;amp;&amp;amp;z&amp;amp;i and post_&amp;amp;&amp;amp;z&amp;amp;i Means with Standard Error Bars";                                                                   
	run;                                                                                                                                                                                                                                                                           
	ods html close;                                                                                                                         
	ods listing; 
 
%end;
%mend;

%RunPlot(macrovars3, 2)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 15:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803584#M316423</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2022-03-23T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sgplots of multiple variables in macro do loop - but only first variable is graphed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803598#M316432</link>
      <description>&lt;P&gt;From now on, when you are trying to debug macros, you need to turn on this option&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This makes the LOG much more readable and makes clear that CHF is plotted and later VALVE is plotted, as the TITLE statements in the LOG indicate this clearly.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The problem is here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods html file='scatterplot.html' path='.' style=styles.statistical;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plots always go to the same .html file, and so the first one is overwritten by the next one, and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to do yourself a favor and name your variables PRE_CHF and POST_CHF and so on, instead of the much less meaningful prez1 and postz1 and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 16:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803598#M316432</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-23T16:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sgplots of multiple variables in macro do loop - but only first variable is graphed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803601#M316435</link>
      <description>Thanks Paige - I tried rerunning with the statement:&lt;BR /&gt;&lt;BR /&gt;ods html file="scatterplot_&amp;amp;i.html" path='.' style=styles.statistical;&lt;BR /&gt;&lt;BR /&gt;but I'm still getting duplicate graphs.</description>
      <pubDate>Wed, 23 Mar 2022 16:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803601#M316435</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2022-03-23T16:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc sgplots of multiple variables in macro do loop - but only first variable is graphed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803602#M316436</link>
      <description>&lt;P&gt;I think you need to change the ODS HTML as shown below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods html file="scatterplot_&amp;amp;i..html" path='.' style=styles.statistical;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and also remove the RESET option from ODS GRAPHICS.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 16:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sgplots-of-multiple-variables-in-macro-do-loop-but-only/m-p/803602#M316436</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-23T16:56:59Z</dc:date>
    </item>
  </channel>
</rss>

