<?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 Creating a graph with a moving date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874746#M38831</link>
    <description>&lt;P&gt;I need to create an automated report with a moving date. One that goes back a few weeks to present (with a 3 day lag).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a macro for the date here:&lt;/P&gt;&lt;P&gt;%let start =&amp;nbsp; %sysfunc(intnx(day,%sysfunc(today()),-22), date9.);&lt;BR /&gt;%let end =&amp;nbsp; %sysfunc(intnx(day,%sysfunc(today()),-3), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to create a line graph that will only show data between the 'start' and 'end' variables. Code for graph:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sgplot data=nine noborder;&lt;BR /&gt;where date &amp;gt;= '&amp;amp;start'd and date &amp;lt;= '&amp;amp;end'd;&lt;BR /&gt;vline date / response=admit_ma y2axis lineattrs=(color=blue thickness=4)&lt;BR /&gt;DATALABELPOS=data name='c';&lt;BR /&gt;xaxis discreteorder=data display=(noline nolabel noticks) fitpolicy=thin;&lt;BR /&gt;y2axis display=(noline noticks) grid label='New COVID Hospital Admissions' values=(0 to 1.0 by 0.1) offsetmin=0;&lt;BR /&gt;keylegend 'c'/ title='' linelength=24 noborder;&lt;BR /&gt;label admit_ma='Number of new admissions';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this probably isn't the best way, but I am modeling after an old code that was being used. The error I get is based off the date variables:&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;start'd.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;end'd.&lt;/P&gt;&lt;P&gt;Error: Syntax error while parsing WHERE clause.&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 20:47:35 GMT</pubDate>
    <dc:creator>scolitti1</dc:creator>
    <dc:date>2023-05-09T20:47:35Z</dc:date>
    <item>
      <title>Creating a graph with a moving date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874746#M38831</link>
      <description>&lt;P&gt;I need to create an automated report with a moving date. One that goes back a few weeks to present (with a 3 day lag).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a macro for the date here:&lt;/P&gt;&lt;P&gt;%let start =&amp;nbsp; %sysfunc(intnx(day,%sysfunc(today()),-22), date9.);&lt;BR /&gt;%let end =&amp;nbsp; %sysfunc(intnx(day,%sysfunc(today()),-3), date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is to create a line graph that will only show data between the 'start' and 'end' variables. Code for graph:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sgplot data=nine noborder;&lt;BR /&gt;where date &amp;gt;= '&amp;amp;start'd and date &amp;lt;= '&amp;amp;end'd;&lt;BR /&gt;vline date / response=admit_ma y2axis lineattrs=(color=blue thickness=4)&lt;BR /&gt;DATALABELPOS=data name='c';&lt;BR /&gt;xaxis discreteorder=data display=(noline nolabel noticks) fitpolicy=thin;&lt;BR /&gt;y2axis display=(noline noticks) grid label='New COVID Hospital Admissions' values=(0 to 1.0 by 0.1) offsetmin=0;&lt;BR /&gt;keylegend 'c'/ title='' linelength=24 noborder;&lt;BR /&gt;label admit_ma='Number of new admissions';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this probably isn't the best way, but I am modeling after an old code that was being used. The error I get is based off the date variables:&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;start'd.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;end'd.&lt;/P&gt;&lt;P&gt;Error: Syntax error while parsing WHERE clause.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 20:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874746#M38831</guid>
      <dc:creator>scolitti1</dc:creator>
      <dc:date>2023-05-09T20:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a graph with a moving date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874754#M38832</link>
      <description>&lt;P&gt;First point, for actual comparison values do not create text values, just use the date numeric and&lt;/P&gt;
&lt;P&gt;that will solve the second: macro variables do not resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless you have a need to display the date as text like 01MAY2023 somewhere else in the code you would be better off with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let start =  %sysfunc(intnx(day,%sysfunc(today()),-22));
%let end =  %sysfunc(intnx(day,%sysfunc(today()),-3));


proc sgplot data=nine noborder;
where date &amp;gt;=&amp;amp;start. and date &amp;lt;= &amp;amp;end.;
vline date / response=admit_ma y2axis lineattrs=(color=blue thickness=4)
DATALABELPOS=data name='c';
xaxis discreteorder=data display=(noline nolabel noticks) fitpolicy=thin;
y2axis display=(noline noticks) grid label='New COVID Hospital Admissions' values=(0 to 1.0 by 0.1) offsetmin=0;
keylegend 'c'/ title='' linelength=24 noborder;
label admit_ma='Number of new admissions';
run;&lt;/PRE&gt;
&lt;P&gt;Since SAS does allow compound comparisons I typically would use this since it is a bit easier to follow intent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;where &amp;amp;start. &amp;lt;= date &amp;lt;= &amp;amp;end.;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 20:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874754#M38832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-09T20:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a graph with a moving date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874761#M38833</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="scolitti1_0-1683666071620.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83764iA5B9F9BE45ECBAAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="scolitti1_0-1683666071620.png" alt="scolitti1_0-1683666071620.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I implemented your suggestions. Did not seem to work&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 21:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-a-graph-with-a-moving-date/m-p/874761#M38833</guid>
      <dc:creator>scolitti1</dc:creator>
      <dc:date>2023-05-09T21:01:57Z</dc:date>
    </item>
  </channel>
</rss>

