<?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 date formatted variable  to non-date numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31752#M6114</link>
    <description>Thank you very much Cynthia.&lt;BR /&gt;
&lt;BR /&gt;
That really worked!!</description>
    <pubDate>Thu, 24 Jul 2008 19:12:49 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-07-24T19:12:49Z</dc:date>
    <item>
      <title>SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31747#M6109</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
How can I convert a date formatted variable to a regular formatted (e.g. 8.) numeric variable?&lt;BR /&gt;
&lt;BR /&gt;
If I have a variable with an YYMMDDn8. format, how I can transfer that value (e.g. 20051210) to a new numeric variable?  That new variable should have just an 8. format but I am interested to keep all the 8 digits.  I have tried different ways already but I am getting always the YYMMDDn8. format. &lt;BR /&gt;
&lt;BR /&gt;
In other words, how do I change the YYMMDDn8. date format without losing the 8 digits?&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Thu, 17 Jul 2008 01:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31747#M6109</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-17T01:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31748#M6110</link>
      <description>A SAS DATE variable is a numeric value internally, representing a count of days since Jan 1 1960.  You can assign a new SAS variable in a DATA step to your SAS DATE variable, and you will need to use both the PUT function and the INPUT function in order to create a SAS numeric variable containng the 8 digits as you have explained.  What you are accomplishing is that you are first "formatting" the SAS DATE variable.  Then you are "inputting" the formatted string using a specific INFORMAT.&lt;BR /&gt;
&lt;BR /&gt;
Another option is again to use the PUT function in an assignment statement, however you can declare the SAS NUMERIC variable with a LENGTH statement, but this statement must occur before the assignment statement.&lt;BR /&gt;
&lt;BR /&gt;
Personally, my experience is that it's better to know how you are expressing variable values through PUT and INPUT functions, rather than letting SAS automatically convert variable values on your behalf in a DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 17 Jul 2008 02:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31748#M6110</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-07-17T02:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31749#M6111</link>
      <description>Hi:&lt;BR /&gt;
  To me, the question is what are you really trying to do, or what is your purpose for treating the date as a "raw" number????&lt;BR /&gt;
For example, the date, 12/10/2005 or 10Dec2005 or 20051210 -- can be represented many different ways, but no matter which representation we choose, it ALWAYS means the 10th of December 2005. 20051210 depends on context for meaning.&lt;BR /&gt;
&lt;BR /&gt;
So, if "20051210" looked like any of these numbers, with punctuation added, then none of us would immediately think of Dec 10th 2005 as the meaning for the number.&lt;BR /&gt;
$200,512.10 or&lt;BR /&gt;
200-51-210&lt;BR /&gt;
20,051,210&lt;BR /&gt;
20.051.210&lt;BR /&gt;
200.512,10&lt;BR /&gt;
&lt;BR /&gt;
SAS stores a date as a number on a timeline -- if Jan 1, 1960 is "day 0" on the timeline, then Dec 10th 2005 represents 16780 days FROM Jan 1, 1960. And, since there were days BEFORE Jan 1, 1960, the SAS internal timeline allows for dates to go back to the 1500's. But let's just take one date, for example, Nov 15th 1950 was 3334 days BEFORE Jan 1, 1960 so the internal number for that date is -3334. The internal number for Dec 10th 2005 is 16780; the internal number for &lt;BR /&gt;
Dec 10th 2999 is 379831; the internal number for Dec 10th 1600 is -131143. I think that's pretty cool how SAS stores dates in this fashion. &lt;BR /&gt;
&lt;BR /&gt;
Once your date is stored as that "timeline version" of the number, there is no ambiguity about what the number can mean inside SAS when the variable is used. For example, let's say I want to find out how many days it's been between Dec 10th 2005 and today (July 16th 2008), I can do something like this in SAS:&lt;BR /&gt;
[pre]&lt;BR /&gt;
elapsed = today() - datevar;&lt;BR /&gt;
elapsed = 17729 - 16780;  &amp;lt;----what SAS does internally&lt;BR /&gt;
elapsed = 949 = almost 3 years which is the right number of days&lt;BR /&gt;
VERSUS&lt;BR /&gt;
20080716 - 20051210 = 29506???? this is a meaningless number&lt;BR /&gt;
[/pre]&lt;BR /&gt;
         &lt;BR /&gt;
&lt;BR /&gt;
But, that subtraction only works IF the dates are stored as their timeline versions of the number. As you can see, subtracting the 8 digit version of the number does not accurately reflect the correct number of elapsed days.&lt;BR /&gt;
                                                                                   &lt;BR /&gt;
If it's annoying to see 16780 or -3334, when you want to see dates, the solution is very simple -- just assign a permanent format (such as mmddyy10. or yymmddn8.) to the date variable. Most SAS procedures will use a permanently assigned format to display a date value. If you want to change the displayed value for a date, you can change the permanent format by using a different format. So the same timeline version of the dates can be displayed different ways without affecting how SAS will be able to use them internally: &lt;BR /&gt;
[pre]&lt;BR /&gt;
format to  -- Display As --&lt;BR /&gt;
 use        -3334      16780&lt;BR /&gt;
mmddyy10.  11/15/1950  12/10/2005&lt;BR /&gt;
year4.     1950        2005 &lt;BR /&gt;
monyy7.    NOV1950     DEC2005 &lt;BR /&gt;
date9.     15NOV1950   10DEC2005 &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Do you really want Dec 10th 2005 to be to be internally stored as the number, 20051210 (20 milltion, 51 thousand, Two-hundred and 10)?? It will make your unformatted date easy to read, but will pretty much render the value useless for calculating how long or how old or elapsed time.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 17 Jul 2008 04:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31749#M6111</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-17T04:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31750#M6112</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your message.  The reason for treating the date as a "raw" number is because I have to merge that data file with another data file using the date as an identifier.  Unfortunately the date on the other data file was defined as a "raw" number with 8 digits in the form yyyymmdd instead of using the date format.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.</description>
      <pubDate>Thu, 17 Jul 2008 05:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31750#M6112</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-17T05:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31751#M6113</link>
      <description>Hi:&lt;BR /&gt;
  Well, rather than turn your SAS date into a "raw" number, I'd be very tempted to turn the "raw" number from the other file into a SAS date value. Let's say that your "raw" number was called JUSTANUM:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data testit;&lt;BR /&gt;
  justanum = 20051210;&lt;BR /&gt;
  newdate = input(put(justanum,8.),yymmdd8.);&lt;BR /&gt;
  output;&lt;BR /&gt;
  justanum = 19501115;&lt;BR /&gt;
  newdate = input(put(justanum,8.),yymmdd8.);&lt;BR /&gt;
  output;&lt;BR /&gt;
run;&lt;BR /&gt;
      &lt;BR /&gt;
proc print data=testit;&lt;BR /&gt;
  title 'convert "raw" date to SAS date value';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
and the result would be the correct internal "timeline" date values:&lt;BR /&gt;
[pre]&lt;BR /&gt;
convert "raw" date to SAS date value&lt;BR /&gt;
     &lt;BR /&gt;
Obs    justanum    newdate&lt;BR /&gt;
      &lt;BR /&gt;
 1     20051210      16780&lt;BR /&gt;
 2     19501115      -3334&lt;BR /&gt;
   &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 17 Jul 2008 06:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31751#M6113</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-17T06:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31752#M6114</link>
      <description>Thank you very much Cynthia.&lt;BR /&gt;
&lt;BR /&gt;
That really worked!!</description>
      <pubDate>Thu, 24 Jul 2008 19:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31752#M6114</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-24T19:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date formatted variable  to non-date numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31753#M6115</link>
      <description>Scott,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your advices.  Those were very helpful.  You did help me to better understand the PUT and INPUT  functions that I later used.

Message was edited by: Caramel</description>
      <pubDate>Thu, 24 Jul 2008 19:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-formatted-variable-to-non-date-numeric-variable/m-p/31753#M6115</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-24T19:22:10Z</dc:date>
    </item>
  </channel>
</rss>

