<?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: Convert date to a quarter-Year when some dates are missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510077#M137231</link>
    <description>&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201247.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201247.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Nov 2018 21:19:57 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-02T21:19:57Z</dc:date>
    <item>
      <title>Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510069#M137224</link>
      <description>&lt;P&gt;I have a date variable in YYMMDD10. format. e.g. 2017-06-26, I want to create another variable with Quarter and Year&amp;nbsp; of the date variable .e.g Q2 2017 (please note the space in between). Some of the values for the date variable is missing and I&amp;nbsp;cant delete&amp;nbsp;rows with missing values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following&amp;nbsp;code only works when there is no missing&amp;nbsp;date values and&amp;nbsp; returns quarter as Year-Quarter&amp;nbsp;. eg. 2017Q2&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;data want; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;EndQuarter=put(EndDate, &lt;FONT color="#008080" face="Courier New" size="2"&gt;yyq.&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;But For missing date values, following code did not work.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;data want; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; EndDate=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; EndQuarter=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; EndQuarter=put(EndDate, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yyq.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Any suggestion for changes?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thank you.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510069#M137224</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2018-11-02T21:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510073#M137227</link>
      <description>&lt;P&gt;Your code works fine for me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data w;

enddate= input('2017-06-26',yymmdd10.);
length EndQuarter $10;
if EndDate=. then EndQuarter=' ';

else EndQuarter=put(EndDate, yyq6.);
output;
enddate=.;

if EndDate=. then EndQuarter=' ';

else EndQuarter=put(EndDate, yyq6.);
output;
format enddate yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510073#M137227</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-02T21:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510074#M137228</link>
      <description>&lt;P&gt;Why do you need to define your quarter year date as character? You can just leave it as a SAS date and then apply the date format you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;EndQuarter=EndDate;
format EndQuarter yyq.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510074#M137228</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-02T21:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510076#M137230</link>
      <description>&lt;P&gt;I got this error with the suggested code:&lt;/P&gt;&lt;P&gt;The format $YYQ was not found or could not be loaded.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510076#M137230</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2018-11-02T21:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510077#M137231</link>
      <description>&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201247.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201247.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510077#M137231</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-02T21:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510081#M137235</link>
      <description>The dollar sign means that your date variable is not a SAS date, but it's a character. So you first have to import it as a date using INPUT and then convert it to YYQ using PUT, or apply the format. This is easy to see in the future, because it has the $ sign in front of the format and that's only true for character formats, not numeric formats.</description>
      <pubDate>Fri, 02 Nov 2018 21:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510081#M137235</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-02T21:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510093#M137242</link>
      <description>&lt;PRE&gt;data want; set have; 

if EndDate=. then EndQuarter=.; &amp;lt;= creates endquarter as numeric

else EndQuarter=put(EndDate, yyq.); &amp;lt;= attempts to put non-numeric value Q into a number.

run;
&lt;/PRE&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want; 
   set have; 
   length Enddate $ 6.;
   if EndDate=. then EndQuarter= ' ';

   else EndQuarter=put(EndDate, yyq.);

run;
&lt;/PRE&gt;
&lt;P&gt;Though for most purposes I would just use the format yyq. for Enddate .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 22:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/510093#M137242</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-02T22:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert date to a quarter-Year when some dates are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/514930#M138891</link>
      <description>&lt;P&gt;My variable was a string variable , so&amp;nbsp;first I converted to numeric, as Reeza suggested. That did the trick.&amp;nbsp;And then applied the format.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 22:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-date-to-a-quarter-Year-when-some-dates-are-missing/m-p/514930#M138891</guid>
      <dc:creator>d0816</dc:creator>
      <dc:date>2018-11-20T22:09:35Z</dc:date>
    </item>
  </channel>
</rss>

