<?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: SAS Formats with Year and Quarter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674962#M203290</link>
    <description>&lt;PRE&gt;data have;
  input date:BEST12.;
  format date BEST12.;
  datalines;
200001
200002
200003
200004
200101
;
run;

data want;
  set have;
  new_date =yyq(int(date/100),mod(date,100));
  format new_date yyqc6.;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Aug 2020 11:48:40 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-08-06T11:48:40Z</dc:date>
    <item>
      <title>SAS Formats with Year and Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674877#M203256</link>
      <description>&lt;P&gt;I am having a lot of trouble for something that should be easy.&lt;/P&gt;&lt;P&gt;I've used proc import to covert a .txt file to a .sas7bdat file and I am interested in one variable named date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the import coverts it to a BEST12. format and if I try to convert this year and quarter data which looks like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have (BEST 12.)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Want (YYQC6.)&lt;/P&gt;&lt;P&gt;200001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000:1&lt;/P&gt;&lt;P&gt;200002 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000:2&lt;/P&gt;&lt;P&gt;200003 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000:3&lt;/P&gt;&lt;P&gt;200004 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000:4&lt;/P&gt;&lt;P&gt;200101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2001:1&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that if I convert it to YYQC6. I get those dates based on the time from 1960, not the actual year and quarter I want. I could use substr and cats, but that doesn't give me the right format even though it looks like what I want. Any help on how to proceed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is some starting code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date:BEST12.;
  format date BEST12.;
  datalines;
200001
200002
200003
200004
200101
;
run;

proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Aug 2020 23:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674877#M203256</guid>
      <dc:creator>krueg314</dc:creator>
      <dc:date>2020-08-05T23:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats with Year and Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674879#M203258</link>
      <description>&lt;P&gt;When you read 200001 with informat BEST12., this is not a SAS date value representing the first quarter of 2000, and so formatting it with yyqc6. will fail. A valid SAS date value is the number of days since January 1, 1960. So you have to translate the text string 200001 to the text string 2000Q1, and then you can use the informat YYQ. to make this a valid SAS date value. Once it is a valid SAS date value, then formatting it with yyqc6. will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, this works fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date:$6.;
  substr(date,5,1)='Q';
  date_wanted=input(date,yyq6.);
  format date_wanted yyqc6.;
  datalines;
200001
200002
200003
200004
200101
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but in this simple case, there's a simpler solution that does not involve formatting at all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date:$6.;
  substr(date,5,1)=':';
  datalines;
200001
200002
200003
200004
200101
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this has the drawback that the DATE values are text strings, not numbers, and so any calendar function or additional formatting will fail (without additional effort). If your only goal is to display 200001 as 2000:1 then this is fine. If at some point you want to perform arithmetic or boolean logic with this value, you probably will want the first solution.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 00:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674879#M203258</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-06T00:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats with Year and Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674893#M203261</link>
      <description>&lt;P&gt;So you read the string&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;200001&lt;/FONT&gt; is if it was the number&amp;nbsp;&lt;FONT face="courier new,courier"&gt;200,001&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;but to use the YYQC format you need to have a date value instead. That is one of the problems with using PROC IMPORT,&amp;nbsp; it is forced to guess how to read the data so it assumed the string of digits represented a number.&amp;nbsp; It sounds like you want to treat that string as meaning the first quarter of 2000.&amp;nbsp; And 200002 as the second quarter.&lt;/P&gt;
&lt;P&gt;You could convert your number into a date vlaue, then you could use that format to display it.&lt;/P&gt;
&lt;P&gt;So here a simplified data step to create your example data (note there is no need for format or informat for simple numbers).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date ;
datalines;
200001
200002
200003
200004
200101
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here is a data step to read the existing dataset an convert the values of DATE into actual date value and attach the YYQC6. format specification to it.&amp;nbsp; You can use INT() and MOD() to split the number in the year and qtr value. You can use MDY() to make a date value and INTNX() to move it to the right quarter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  date = intnx('qtr',mdy(1,1,int(date/100)),mod(date,100)-1);
  format date yyqc6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs      date

 1     2000:1
 2     2000:2
 3     2000:3
 4     2000:4
 5     2001:1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 03:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674893#M203261</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-06T03:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Formats with Year and Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674962#M203290</link>
      <description>&lt;PRE&gt;data have;
  input date:BEST12.;
  format date BEST12.;
  datalines;
200001
200002
200003
200004
200101
;
run;

data want;
  set have;
  new_date =yyq(int(date/100),mod(date,100));
  format new_date yyqc6.;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 11:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Formats-with-Year-and-Quarter/m-p/674962#M203290</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-06T11:48:40Z</dc:date>
    </item>
  </channel>
</rss>

