<?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: Export regression plots (using BY statement) and display trendline and r2 value on each plot in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963912#M375477</link>
    <description>This is a great and clean solution, but your other solution was perfect. Thank you so very much for taking the time to help me!</description>
    <pubDate>Wed, 09 Apr 2025 16:45:07 GMT</pubDate>
    <dc:creator>camper</dc:creator>
    <dc:date>2025-04-09T16:45:07Z</dc:date>
    <item>
      <title>Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963739#M375408</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;I am trying to display several regression plots, using 9.4.&amp;nbsp; Each plot needs to have the regression line and r2 value.&amp;nbsp;An error in my code shows that each plot has the same R2. Eventually I want to save/export all of the plots in a pdf.&amp;nbsp; I don't want to display the chart data that my code is generating.&amp;nbsp; I have found several examples, online, and this is the shortest code, so I'm submitting it to you.&amp;nbsp; I'm new to ods and macros, so I'm not sure how to trouble shoot this code.&amp;nbsp; I've attached some sample code, for 2 stations.&amp;nbsp; I have 132 stations in the full dataset.&amp;nbsp; Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=testing; by station_nm; run;&lt;BR /&gt;ods graphics off;&lt;BR /&gt;proc reg data=testing ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; model q_CFS = EstQ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; by station_nm;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ods output fitstatistics=R2;&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set R2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if _n_ = 1 then call symput('R2', cValue2);&lt;BR /&gt;run;&lt;BR /&gt;proc sgplot data=testing noautolegend ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by station_nm;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; reg y=q_CFS x=EstQ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; inset "R2 = &amp;amp;R2"/ position=topleft;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 17:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963739#M375408</guid>
      <dc:creator>camper</dc:creator>
      <dc:date>2025-04-08T17:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963740#M375409</link>
      <description>&lt;P&gt;Is your question about the error or about getting charts into PDF, or both?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is about the error, you need to show us the log with the error (we need to see the entire log, not just the error messages). Copy the log as text (not screen capture) and then paste the log into the window that appears when you click on the &amp;lt;/&amp;gt; icon&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1715196634946.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96351i414DE7EE2D1B5DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1715196634946.png" alt="PaigeMiller_0-1715196634946.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 18:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963740#M375409</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-08T18:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963807#M375430</link>
      <description>&lt;P&gt;I think you need to make a macro to get job done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='C:\Users\xiakeshan\Documents\Downloads\Testing.csv' out=testing dbms=csv replace;
run;

proc sort data=testing; by station_nm; run;
proc freq data=testing noprint;
table station_nm/out=station_nm;
run;

%macro reg_plot(station_nm=);
ods select none;
proc reg data=testing ;
    where station_nm="&amp;amp;station_nm.";
    model q_CFS = EstQ/rsquare ;
    ods output fitstatistics=R2;
run;
ods select all;
data _null_;
   set R2;
   if _n_=1 then call symputx('R2', cValue2);
run;
proc sgplot data=testing noautolegend ;
    where station_nm="&amp;amp;station_nm.";
      reg y=q_CFS x=EstQ;
      inset "R2 = &amp;amp;R2"/ position=topleft;
run;
%mend;


ods pdf file='c:\temp\want.pdf' style=htmlblue;
data _null_;
 set station_nm;
 call execute(catt('%nrstr(%reg_plot)(station_nm=',station_nm,')'));
run;
ods pdf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 01:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963807#M375430</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-09T01:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963824#M375434</link>
      <description>&lt;P&gt;BTW, Can not you use the default graph of PROC REG?&lt;/P&gt;
&lt;PRE&gt;proc import datafile='C:\Users\xiakeshan\Documents\Downloads\Testing.csv' out=testing dbms=csv replace;
run;

proc sort data=testing; by station_nm; run;





ods pdf file='c:\temp\want.pdf' style=htmlblue;
ods select   FitPlot;
proc reg data=testing ;
    by station_nm;
    model q_CFS = EstQ/rsquare ;
run;
ods pdf close;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1744185336190.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106079i8EA523E1B6E77B2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1744185336190.png" alt="Ksharp_0-1744185336190.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 07:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963824#M375434</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-09T07:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963910#M375475</link>
      <description>Thank you for replying! The 'error' was not in the log. Better stated: Mistakes in my coding was causing each plot to have the same R2 as each other. Thank you!</description>
      <pubDate>Wed, 09 Apr 2025 16:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963910#M375475</guid>
      <dc:creator>camper</dc:creator>
      <dc:date>2025-04-09T16:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963911#M375476</link>
      <description>Thank you so much!! The output is exactly what I was trying to do! Many, many thanks.</description>
      <pubDate>Wed, 09 Apr 2025 16:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963911#M375476</guid>
      <dc:creator>camper</dc:creator>
      <dc:date>2025-04-09T16:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963912#M375477</link>
      <description>This is a great and clean solution, but your other solution was perfect. Thank you so very much for taking the time to help me!</description>
      <pubDate>Wed, 09 Apr 2025 16:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963912#M375477</guid>
      <dc:creator>camper</dc:creator>
      <dc:date>2025-04-09T16:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Export regression plots (using BY statement) and display trendline and r2 value on each plot</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963914#M375479</link>
      <description>Upon reflection... I think the charts with the most info will be terrific. So thanks for offering 2 solutions!</description>
      <pubDate>Wed, 09 Apr 2025 16:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-regression-plots-using-BY-statement-and-display-trendline/m-p/963914#M375479</guid>
      <dc:creator>camper</dc:creator>
      <dc:date>2025-04-09T16:59:32Z</dc:date>
    </item>
  </channel>
</rss>

