<?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: Date Formatting in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506164#M1266</link>
    <description>&lt;P&gt;You would make your life sooooo much easier if you used actual SAS dates instead of a variable with values like 201701. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also don't need to format the values before you use them in PROC SQL. Use formats only when a human has to view the results in an understandable form; PROC SQL doesn't care, it can use the actual date values, so there's no point in formatting them to be actual readable dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
     begin_date=mdy(1,1,2017);
     end_date=intnx('month',begin_date,12,'s')-1;
     /* If you want more than a 12 month interval, replace 12 with the number of months you want */
     call symputx('begin_date',begin_date);
     call symputx('end_date',end_date);
run;

proc sql;
     ...
     where t2.date between &amp;amp;begin_date and &amp;amp;end_date;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Side note: I can't test this right now, but I do not remember if the BETWEEN operator will select the observation if the t2.date value is exactly equal to &amp;amp;begin_date or exactly equal to &amp;amp;end_date. In other words, I don't remember if BETWEEN uses greater than and less than; or greater than or equal to and less than or equal to. But you can test this and modify the code accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Oct 2018 21:09:09 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-10-19T21:09:09Z</dc:date>
    <item>
      <title>Date Formatting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506159#M1264</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help fixing my code, I am trying to writing a code that evaluates the performance of certains observations in my data over several monthly periods. I created a code that works but a bit tedious. To evaluate a perfomance over 12 months, I manually count 12 periods to find the ending date. As follow:&lt;/P&gt;&lt;P&gt;January - beginning_date=201701 - ending_date=201712&lt;/P&gt;&lt;P&gt;February -&amp;nbsp;&lt;SPAN&gt;beginning_date=201702 - ending_date=201801&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;etc...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's my sample code below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%beginning_date= 201701;
%ending_date= 201712;


PROC SQL;
	CREATE TABLE PERFORMANCE AS 
		SELECT t1.*,  
			t2.* 
		FROM DATA_X t1
			LEFT JOIN DATA_Y t2 ON(t1.A=t2.B)
				WHERE t2.DATE BETWEEN &amp;amp;beginning_date. AND &amp;amp;ending_date.;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am now looking for a way to automate the counting process so that I can a performance over a 12, 18, 24 months. I used the code below but I am getting the following error message:&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !!,&lt;BR /&gt;*, **, +, -, /, AND, ||.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The DATE variable in my table is numeric not sure with values such as year/month 201701, 201702, etc..&lt;/P&gt;&lt;P&gt;Any idea or suggestions, thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let beginning_date=201701 ; 

*Macro variable date;

DATA _null_;
DATE=&amp;amp;beginning_date.;
CALL SYMPUT("date_begin_perfo12", PUT(INTNX('month',input("&amp;amp;beginning_date.",yymmn6.),0,'end'),Date9.));
CALL SYMPUT("date_end_perfo12", PUT(INTNX('month',input("&amp;amp;beginning_date.",yymmn6.),+12,'end'),Date9.));
RUN;

%put &amp;amp;date_begin_perfo12.;
%put &amp;amp;date_end_perfo12.;

PROC SQL;
	CREATE TABLE PERFORMANCE AS 
		SELECT t1.*,  
			t2.* 
		FROM DATA_X t1
			LEFT JOIN DATA_Y t2 ON(t1.A=t2.B)
				WHERE t2.DATE BETWEEN &amp;amp;date_begin_perfo12. AND &amp;amp;date_end_perfo12.;
QUIT;&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;</description>
      <pubDate>Fri, 19 Oct 2018 20:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506159#M1264</guid>
      <dc:creator>samface</dc:creator>
      <dc:date>2018-10-19T20:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date Formatting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506160#M1265</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;WHERE&lt;/SPAN&gt; t2&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;DATE&lt;/SPAN&gt; BETWEEN "&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;date_begin_perfo12&lt;SPAN class="token punctuation"&gt;."d&lt;/SPAN&gt; AND "&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;date_end_perfo12&lt;SPAN class="token punctuation"&gt;."d&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 20:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506160#M1265</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-19T20:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Date Formatting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506164#M1266</link>
      <description>&lt;P&gt;You would make your life sooooo much easier if you used actual SAS dates instead of a variable with values like 201701. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also don't need to format the values before you use them in PROC SQL. Use formats only when a human has to view the results in an understandable form; PROC SQL doesn't care, it can use the actual date values, so there's no point in formatting them to be actual readable dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
     begin_date=mdy(1,1,2017);
     end_date=intnx('month',begin_date,12,'s')-1;
     /* If you want more than a 12 month interval, replace 12 with the number of months you want */
     call symputx('begin_date',begin_date);
     call symputx('end_date',end_date);
run;

proc sql;
     ...
     where t2.date between &amp;amp;begin_date and &amp;amp;end_date;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Side note: I can't test this right now, but I do not remember if the BETWEEN operator will select the observation if the t2.date value is exactly equal to &amp;amp;begin_date or exactly equal to &amp;amp;end_date. In other words, I don't remember if BETWEEN uses greater than and less than; or greater than or equal to and less than or equal to. But you can test this and modify the code accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 21:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Date-Formatting/m-p/506164#M1266</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-19T21:09:09Z</dc:date>
    </item>
  </channel>
</rss>

