<?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: Formatting Variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88466#M25255</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Art suggested the first step is to convert all dates to SAS dates.&amp;nbsp; You do not &lt;EM&gt;need&lt;/EM&gt; to do so here, but it is almost always a best practice.&amp;nbsp; Once dates are converted they can be used to merge or join the tables.&amp;nbsp; The formats currently assigned have nothing to do with the problem it is the stored values that you need to deal with.&amp;nbsp; Conside the following simple example of conversion of both numeric and character dates.&lt;/P&gt;&lt;P&gt;data char;&lt;/P&gt;&lt;P&gt;input cdate $6.;&lt;/P&gt;&lt;P&gt;date = mdy(input(substr(cdate,5,2),2.),01,input(substr(cdate,1,4),4.));&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;199101&lt;/P&gt;&lt;P&gt;199202&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data num;&lt;/P&gt;&lt;P&gt;input ndate 6.;&lt;/P&gt;&lt;P&gt;date = mdy(mod(ndate,100),01,int(ndate/100));&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;199202&lt;/P&gt;&lt;P&gt;199303&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge char num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;proc print data=want;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the SAS date to appear in the YYYYMM format use the YYMMN6. format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Oct 2012 06:14:18 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2012-10-07T06:14:18Z</dc:date>
    <item>
      <title>Formatting Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88463#M25252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I currently have 2 different formats of the same data. (Basically they are just dates YYYYMM to me).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 of them is in the format " LENGTH 6, FORMAT $6, , INFORMAT $6."&lt;/P&gt;&lt;P&gt;The other is in the format "LENGTH 8, FORMAT BEST12. , INFORMAT 12."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to merge my data based on dates, but the log said that they have to be in the same format first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I convert them into the same format? And Which is a better format to use?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot guys!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 03:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88463#M25252</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-10-07T03:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88464#M25253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would create two new fields that contain SAS dates.&amp;nbsp; However, before going any further, does the one with length 8 actually only contain yyyymm or does it also contain the day of the month?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 04:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88464#M25253</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-07T04:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88465#M25254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It only contains YYYYMM. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 04:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88465#M25254</guid>
      <dc:creator>Benn</dc:creator>
      <dc:date>2012-10-07T04:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88466#M25255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Art suggested the first step is to convert all dates to SAS dates.&amp;nbsp; You do not &lt;EM&gt;need&lt;/EM&gt; to do so here, but it is almost always a best practice.&amp;nbsp; Once dates are converted they can be used to merge or join the tables.&amp;nbsp; The formats currently assigned have nothing to do with the problem it is the stored values that you need to deal with.&amp;nbsp; Conside the following simple example of conversion of both numeric and character dates.&lt;/P&gt;&lt;P&gt;data char;&lt;/P&gt;&lt;P&gt;input cdate $6.;&lt;/P&gt;&lt;P&gt;date = mdy(input(substr(cdate,5,2),2.),01,input(substr(cdate,1,4),4.));&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;199101&lt;/P&gt;&lt;P&gt;199202&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data num;&lt;/P&gt;&lt;P&gt;input ndate 6.;&lt;/P&gt;&lt;P&gt;date = mdy(mod(ndate,100),01,int(ndate/100));&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;199202&lt;/P&gt;&lt;P&gt;199303&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge char num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;proc print data=want;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want the SAS date to appear in the YYYYMM format use the YYMMN6. format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 06:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88466#M25255</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-10-07T06:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88467#M25256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's two good reasons for keeping date values in numeric SAS date vars, being calculation and representation.&lt;/P&gt;&lt;P&gt;SAS Dates are required for the use of date functions such as INTNX and DATEDIFF and are the only valid values that are one "format away" from displaying a date in any way you wish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, you could actually perform the join without converting one of the key columns, &lt;SPAN style="text-decoration: underline;"&gt;if and only if&lt;/SPAN&gt;, your merge could translate to a SQL join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since SQL allow you to match by transformed columns it would just be a matter of finding the right match expression, maybe something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New';"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New';"&gt;on cats(put(SASDATE,year4.),put(SASDATE,month2.)) = cats(CHARDATE)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Oct 2012 08:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Formatting-Variables/m-p/88467#M25256</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-10-08T08:21:35Z</dc:date>
    </item>
  </channel>
</rss>

