<?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: Transforming numeric &amp;quot;10DEC2010:23:00:00&amp;quot; into char &amp;quot;10DEC12&amp;quot;? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109883#M1262</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be very wary of using two-digit years.&amp;nbsp; SAS will select which century they belong to, and that can vary depending on how your options are set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Back to your question, here's how to get the result using a four-digit year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length newvar $ 9;&lt;/P&gt;&lt;P&gt;newvar = put(price_date, datetime20.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That will give you a four-digit year, in date9 format such as 10DEC2010.&amp;nbsp; If you must remove the century, do it at your own risk!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually tested the code this time, and it looks like datetime20 is too wide.&amp;nbsp; It will give you two leading blanks, since only 18 characters are needed.&amp;nbsp; Instead, try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length newvar $9;&lt;/P&gt;&lt;P&gt;newvar = put(price_date, datetime18.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Oct 2012 13:00:47 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2012-10-30T13:00:47Z</dc:date>
    <item>
      <title>Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109877#M1256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a data set that includes a numeric variable called "price_date". It's in the datetime20-format, and appears as "10DEC2010:23:00:00".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to extract all the rows where price_date =&amp;lt; current_date. However, current_date is a character variable that appears as "30OCT12", and it must remain as it is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is: What kind of expression can I use in the mapping of an Extract-transformation, to transform price_date from the numeric format "10DEC2010:23:00:00" into the character format "10DEC12"?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 14:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109877#M1256</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2012-10-29T14:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109878#M1257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you use something like?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat dt datetime18.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat ch $7.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input dt ch;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;10DEC2010:23:00:00 10DEC12&lt;/P&gt;&lt;P&gt;10DEC2010:23:00:00 12DEC12&lt;/P&gt;&lt;P&gt;10DEC2012:23:00:00 09DEC12&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where datepart(dt)&amp;lt;=input(ch,date7.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 14:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109878#M1257</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-29T14:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109879#M1258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, though I was hoping for something I might use as an expression in an Extract-transformation. Should have specified that I'm working in DI Studio. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE: I tried using &lt;STRONG&gt;put(price_date, date7.)&lt;/STRONG&gt;, but then all price_date rows became blank/null in the output data set. If I use &lt;STRONG&gt;put(price_date, 10.0)&lt;/STRONG&gt; I get the number value of the datetime (16076412), so I figure I need to turn it into the number value of the date only, then transform that date value number into date9. Or perhaps there's an easier way?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 14:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109879#M1258</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2012-10-29T14:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109880#M1259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been tinkering with this for a while, and can't seem to make it work. I'd still be very appreciative for any advice on how to turn a numeric value like "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;08DEC2010:23:00:00" (datetime20)&lt;/SPAN&gt; into a character value like "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;08DEC10" (date7)&lt;/SPAN&gt; using an Extract-transformation mapping expression in DI Studio.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 21:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109880#M1259</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2012-10-29T21:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109881#M1260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If they're character variables then they won't compare properly, ie you can say date&amp;lt;price_date and expect the comparison to work properly.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should make them both numbers instead, or in the comparison use INPUT for the current_date. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 04:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109881#M1260</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-10-30T04:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109882#M1261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want this for row selection then this doesn't go to the expression field of a row but belongs into a where or having clause (or as a row selection if you're using the Splitter).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The where clause would look somewhat like:&amp;nbsp; datepart(price_date)=input("&amp;amp;current_date",date9.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here some sample code (pretty much what Art posted already). The code generated by DI Studio should look something along this line (if using a SQL transformation).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let current_date=%sysfunc(today(),date9.);&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; format Price_Date datetime21.;&lt;BR /&gt;&amp;nbsp; do price_date=intnx('dtday',datetime(),-5) to intnx('dtday',datetime(),5) by 20000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run; &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table want as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where datepart(price_date)=input("&amp;amp;current_date",date9.)&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt; quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 10:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109882#M1261</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-10-30T10:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109883#M1262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be very wary of using two-digit years.&amp;nbsp; SAS will select which century they belong to, and that can vary depending on how your options are set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Back to your question, here's how to get the result using a four-digit year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length newvar $ 9;&lt;/P&gt;&lt;P&gt;newvar = put(price_date, datetime20.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That will give you a four-digit year, in date9 format such as 10DEC2010.&amp;nbsp; If you must remove the century, do it at your own risk!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually tested the code this time, and it looks like datetime20 is too wide.&amp;nbsp; It will give you two leading blanks, since only 18 characters are needed.&amp;nbsp; Instead, try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length newvar $9;&lt;/P&gt;&lt;P&gt;newvar = put(price_date, datetime18.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 13:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109883#M1262</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-10-30T13:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109884#M1263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, that worked perfectly! "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;put(price_date, datetime20.)", ack, so simple it hurts. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPDATE: I've realized that I indeed need to use numeric dates in order to perform comparisons. Thanks for the foresight and advice, everyone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 13:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109884#M1263</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2012-10-30T13:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming numeric "10DEC2010:23:00:00" into char "10DEC12"?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109885#M1264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also note the added comment, about switching to datetime18.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More important, note that some of the posters here were thinking ahead about how you would use the results.&amp;nbsp; While I answered the question, the results may not be useful.&amp;nbsp; When you compare character strings, "01" &amp;lt; "02" no matter what the month and years are.&amp;nbsp; So "01DEC12" &amp;lt; "02JAN10" as far as SAS is concerned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 13:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Transforming-numeric-quot-10DEC2010-23-00-00-quot-into-char-quot/m-p/109885#M1264</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-10-30T13:44:23Z</dc:date>
    </item>
  </channel>
</rss>

