<?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 SAS EG coding for date in character format and automating process for previous quarters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-coding-for-date-in-character-format-and-automating/m-p/830165#M328028</link>
    <description>&lt;P&gt;I'm usually utilizing SAS EG for simple automated pulls and using the PROMPT option to choose to go back so many quarters or months.&amp;nbsp; However since the database I am working with right now utilizes a Character format, the SAS system does not properly recognize it as a date and therefore I can not utilize the date format ( example 20220312 instead of 12Mar2022).&amp;nbsp; So i have to utilize a CASE WHEN SUBSTR option to break down the character date into quarters that fall between the WHERE option dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any method in SAS EG that you can tell the code to search for the last 5 quarters of data automatically without having to input dates in it and changing the dates every quarter? It works as is, but I prefer to just automate it as this code below is in several dozen other EGP's and would hate to miss a replacement next quarter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the parts to the code which I have to utilize every quarter;&lt;/P&gt;&lt;P&gt;CASE WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202204' AND '202206' THEN '2022Q2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202201' AND '202203' THEN '2022Q1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202110' AND '202112' THEN '2021Q4'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202107' AND '202109' THEN '2021Q3'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202104' AND '202106' THEN '2021Q2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 'OTHER' END AS ACQ_Q,&lt;/P&gt;&lt;P&gt;&amp;nbsp;WHERE SUBSTR(WLM.ACQ_DTE, 1, 6) BETWEEN '202104' AND '202206'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2022 17:47:06 GMT</pubDate>
    <dc:creator>btwovegas</dc:creator>
    <dc:date>2022-08-24T17:47:06Z</dc:date>
    <item>
      <title>SAS EG coding for date in character format and automating process for previous quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-coding-for-date-in-character-format-and-automating/m-p/830165#M328028</link>
      <description>&lt;P&gt;I'm usually utilizing SAS EG for simple automated pulls and using the PROMPT option to choose to go back so many quarters or months.&amp;nbsp; However since the database I am working with right now utilizes a Character format, the SAS system does not properly recognize it as a date and therefore I can not utilize the date format ( example 20220312 instead of 12Mar2022).&amp;nbsp; So i have to utilize a CASE WHEN SUBSTR option to break down the character date into quarters that fall between the WHERE option dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any method in SAS EG that you can tell the code to search for the last 5 quarters of data automatically without having to input dates in it and changing the dates every quarter? It works as is, but I prefer to just automate it as this code below is in several dozen other EGP's and would hate to miss a replacement next quarter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the parts to the code which I have to utilize every quarter;&lt;/P&gt;&lt;P&gt;CASE WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202204' AND '202206' THEN '2022Q2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202201' AND '202203' THEN '2022Q1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202110' AND '202112' THEN '2021Q4'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202107' AND '202109' THEN '2021Q3'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN SUBSTR(WLM.ACQ_DTE, &lt;STRONG&gt;1&lt;/STRONG&gt;, &lt;STRONG&gt;6&lt;/STRONG&gt;) BETWEEN '202104' AND '202106' THEN '2021Q2'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE 'OTHER' END AS ACQ_Q,&lt;/P&gt;&lt;P&gt;&amp;nbsp;WHERE SUBSTR(WLM.ACQ_DTE, 1, 6) BETWEEN '202104' AND '202206'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 17:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-EG-coding-for-date-in-character-format-and-automating/m-p/830165#M328028</guid>
      <dc:creator>btwovegas</dc:creator>
      <dc:date>2022-08-24T17:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS EG coding for date in character format and automating process for previous quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-coding-for-date-in-character-format-and-automating/m-p/830183#M328036</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432232"&gt;@btwovegas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have a database with dates as character strings in the format yyyymmdd, and you want all records where the date is within the last 5 quarters. This can be done in a simple query as shown in the following code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The principle is that the text in variable&amp;nbsp;ACQ_DTE is converted to a SAS date, which should be &amp;gt;= tha date that marks the beginning of the 4.complete quarter before the current date, and the current quarter is counted as the 5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want 5 full quarters + the current quarter, then specify -5 instead of -4 to the intnx function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  ACQ_DTE = '20220812'; output;
  ACQ_DTE = '20220412'; output;
  ACQ_DTE = '20220312'; output;
  ACQ_DTE = '20211212'; output;
  ACQ_DTE = '20211012'; output;
  ACQ_DTE = '20210812'; output;
  ACQ_DTE = '20210512'; output;  
  ACQ_DTE = '20210112'; output;
run;

proc sql;
  create table want as
    select 
      ACQ_DTE,
      put(input(ACQ_DTE,yymmdd8.),yyq6.) as ACQ_Q
    from have
    where input(ACQ_DTE,yymmdd8.) &amp;gt;= intnx('quarter',date(),-4,'begin');
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2022 20:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-EG-coding-for-date-in-character-format-and-automating/m-p/830183#M328036</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-08-24T20:28:15Z</dc:date>
    </item>
  </channel>
</rss>

