<?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: Renaming and formatting date variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131436#M35741</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What results do you get for your new dob variable? Show the actual input and resulting values for some records. Otherwise it is a bit hard to even know where to start.&lt;/P&gt;&lt;P&gt;It may be revealing to show what the value of the original put(mother_dob, 8.) is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Nov 2013 19:39:58 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2013-11-01T19:39:58Z</dc:date>
    <item>
      <title>Renaming and formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131435#M35740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Input file: is an excel file read into SAS. Mother_dob is a numeric variable with the value 20130123 in the file Test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Wanted output file: I want mother_dob with the format yymmddn8&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result I got with the following code: the output file is still showing mother_dob with the yymmdd8. format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I noticed that in my following code after I do the formating of the date variable the values are still showing as in SAS date values. Could you please help me understand why the format yymmddn8 is not getting assigned in the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA final;&lt;/P&gt;&lt;P&gt;SET test(keep=mother_dob obs=1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MOTHER_DOB1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = input(put(left(MOTHER_DOB),8.),YYMMDD8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop MOTHER_DOB ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename MOTHER_DOB1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = MOTHER_DOB;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format MOTHER_DOB yymmddn8.;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I was able to assign mother_dob with yymmddn8. format with the following code but still did not understand why the above code did not work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Modified code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA final;&lt;/P&gt;&lt;P&gt;SET test(keep=mother_dob obs=1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MOTHER_DOB1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = input(put(left(MOTHER_DOB),8.),YYMMDD8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format MOTHER_DOB1 yymmddn8.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop MOTHER_DOB ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename MOTHER_DOB1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = MOTHER_DOB;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please share your thoughts. Thank you all in advance!&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 19:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131435#M35740</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2013-11-01T19:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming and formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131436#M35741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What results do you get for your new dob variable? Show the actual input and resulting values for some records. Otherwise it is a bit hard to even know where to start.&lt;/P&gt;&lt;P&gt;It may be revealing to show what the value of the original put(mother_dob, 8.) is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 19:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131436#M35741</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-11-01T19:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming and formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131437#M35742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Value of dob in the input file:&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;20130123&amp;nbsp; , type numeric&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;With the first set of code I got the value for dob as : 19381, type numeric&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;With second set of code I got the value for dob as :&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;20130123, &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; format yymmddn8.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Hope this helps.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 21:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131437#M35742</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2013-11-01T21:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming and formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131438#M35743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first one doesn't work because you never attached a format to your new variable.&amp;nbsp; Instead you attached it to the one that you dropped.&amp;nbsp; If your variable is numeric then you do NOT want the LEFT() function as that will convert it to a string which will then probably cause the PUT() function to use $8. format instead of the 8. format that it would have used if the value passed it was a number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data final;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set test(keep=mother_dob obs=1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; mother_dob1 = input(put(&lt;SPAN style="text-decoration: line-through; color: #ff0000;"&gt;left(&lt;/SPAN&gt;mother_dob&lt;SPAN style="text-decoration: line-through; color: #ff0000;"&gt;)&lt;/SPAN&gt;,8.),yymmdd8.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; drop mother_dob ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; rename mother_dob1 = mother_dob;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; format mother_dob&lt;SPAN style="color: #ff0000;"&gt;1&lt;/SPAN&gt; yymmddn8.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since your variable is already numeric there is no need to create a new one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data final;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set test ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; mother_dob = input(put(mother_dob,8.),yymmdd8.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; format mother_dob&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt; yymmddn8.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might also want to consider what will happen if you happen to have a smaller number (less than 8 digits) or large number (more than 8 digits) in the variable.&amp;nbsp; How clean is your data source, and given that it is Excel it is probably not very clean.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 22:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131438#M35743</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-01T22:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming and formatting date variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131439#M35744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for your comments, really appreciate it!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 22:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Renaming-and-formatting-date-variables/m-p/131439#M35744</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2013-11-01T22:39:18Z</dc:date>
    </item>
  </channel>
</rss>

