<?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 SAS dates - adding '0's in front of numbers&amp;lt;=9 in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/SAS-dates-adding-0-s-in-front-of-numbers-lt-9/m-p/7470#M784</link>
    <description>Hello,&lt;BR /&gt;
  I have really messy data where I have a date variable and it looks like the following:&lt;BR /&gt;
&lt;BR /&gt;
2/5/04&lt;BR /&gt;
11/25/06&lt;BR /&gt;
5/17/03&lt;BR /&gt;
...etc. &lt;BR /&gt;
&lt;BR /&gt;
I'd like to make it consistent by adding '0's in front of the single digits..so I'd like to make it look like:&lt;BR /&gt;
&lt;BR /&gt;
02/05/04&lt;BR /&gt;
...&lt;BR /&gt;
05/17/03&lt;BR /&gt;
...etc. &lt;BR /&gt;
&lt;BR /&gt;
How do I do this in SAS?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!!!</description>
    <pubDate>Fri, 14 Mar 2008 16:40:20 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-03-14T16:40:20Z</dc:date>
    <item>
      <title>SAS dates - adding '0's in front of numbers&lt;=9</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/SAS-dates-adding-0-s-in-front-of-numbers-lt-9/m-p/7470#M784</link>
      <description>Hello,&lt;BR /&gt;
  I have really messy data where I have a date variable and it looks like the following:&lt;BR /&gt;
&lt;BR /&gt;
2/5/04&lt;BR /&gt;
11/25/06&lt;BR /&gt;
5/17/03&lt;BR /&gt;
...etc. &lt;BR /&gt;
&lt;BR /&gt;
I'd like to make it consistent by adding '0's in front of the single digits..so I'd like to make it look like:&lt;BR /&gt;
&lt;BR /&gt;
02/05/04&lt;BR /&gt;
...&lt;BR /&gt;
05/17/03&lt;BR /&gt;
...etc. &lt;BR /&gt;
&lt;BR /&gt;
How do I do this in SAS?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!!!</description>
      <pubDate>Fri, 14 Mar 2008 16:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/SAS-dates-adding-0-s-in-front-of-numbers-lt-9/m-p/7470#M784</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-03-14T16:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: SAS dates - adding '0's in front of numbers&lt;=9</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/SAS-dates-adding-0-s-in-front-of-numbers-lt-9/m-p/7471#M785</link>
      <description>Hi:&lt;BR /&gt;
  Is your date variable a character variable or a numeric variable?&lt;BR /&gt;
&lt;BR /&gt;
  The method you use to show leading zeroes in the month or the year will depend on whether you're dealing with a character variable value or a numeric variable value.&lt;BR /&gt;
 &lt;BR /&gt;
  Let's assume that your date variable is a numeric variable -- that means that SAS stores the first value not as "2/5/04" but as 16106 -- which represents the number of days between Feb 5, 2004 and Jan 1, 1960 (the SAS zero date). In this instance, a simple FORMAT statement in your PROC PRINT or your procedure would display the date variable's values with leading zeroes.&lt;BR /&gt;
 &lt;BR /&gt;
  On the other hand, if your variable is a character variable, then a FORMAT statement will not work to alter the display of your data values. By far, I think the FORMAT statement method -- is the EASIEST way to handle the display of date variable values. But, that means the you must transform your character date variable into a numeric variable -- that is internally stored as the number of days either before or after Jan 1, 1960. If you are READING raw data into SAS format, then when you read '2/5/04', it is possible, on your INPUT statement, to tell SAS to read the messy number and turn it into a numeric date variable. If you already have messy data and the variable is a character variable, then you can transform it with the INPUT function. &lt;BR /&gt;
 &lt;BR /&gt;
 See the program below for an example of both the INPUT statement and the INPUT function.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** Program;&lt;BR /&gt;
    &lt;BR /&gt;
data messy;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input datevar : mmddyy8. chardate $8.;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2/5/04 2/5/04&lt;BR /&gt;
11/25/06 11/25/06&lt;BR /&gt;
5/17/03 5/17/03&lt;BR /&gt;
11/15/50 11/15/50&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc contents data=messy;&lt;BR /&gt;
  title '1) What are my variables like';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=messy;&lt;BR /&gt;
  title '2) No format -- see internal value';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=messy;&lt;BR /&gt;
  title '3) MMDDYY8 format';&lt;BR /&gt;
  format datevar mmddyy8.;&lt;BR /&gt;
run;&lt;BR /&gt;
      &lt;BR /&gt;
data fixdate;&lt;BR /&gt;
  set messy;&lt;BR /&gt;
  newdate = input(chardate,mmddyy8.);&lt;BR /&gt;
run;&lt;BR /&gt;
     &lt;BR /&gt;
proc contents data=fixdate;&lt;BR /&gt;
  title '4) Is NEWDATE variable character or numeric';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
proc print data=fixdate;&lt;BR /&gt;
  title '5) CHARDATE variable turned into numeric variable NEWDATE';&lt;BR /&gt;
  format datevar newdate mmddyy8.;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 1) What are my variables like&lt;BR /&gt;
&lt;BR /&gt;
The CONTENTS Procedure&lt;BR /&gt;
&lt;BR /&gt;
Data Set Name        WORK.MESSY                              Observations          4 &lt;BR /&gt;
Member Type          DATA                                    Variables             2 &lt;BR /&gt;
Engine               V9                                      Indexes               0 &lt;BR /&gt;
Created              Thursday, March 20, 2008 11:22:45 AM    Observation Length    16&lt;BR /&gt;
Last Modified        Thursday, March 20, 2008 11:22:45 AM    Deleted Observations  0 &lt;BR /&gt;
Protection                                                   Compressed            NO&lt;BR /&gt;
Data Set Type                                                Sorted                NO&lt;BR /&gt;
Label                                                                                &lt;BR /&gt;
Data Representation  WINDOWS_32                                                      &lt;BR /&gt;
Encoding             wlatin1  Western (Windows)                                      &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                                   Engine/Host Dependent Information&lt;BR /&gt;
&lt;BR /&gt;
Data Set Page Size          4096                                                                       &lt;BR /&gt;
Number of Data Set Pages    1                                                                          &lt;BR /&gt;
First Data Page             1                                                                          &lt;BR /&gt;
Max Obs per Page            252                                                                        &lt;BR /&gt;
Obs in First Data Page      4                                                                          &lt;BR /&gt;
Number of Data Set Repairs  0                                                                          &lt;BR /&gt;
File Name                   C:\DOCUME~1\sasczz\LOCALS~1\Temp\SAS Temporary Files\_TD2592\messy.sas7bdat&lt;BR /&gt;
Release Created             9.0101M3                                                                   &lt;BR /&gt;
Host Created                XP_PRO                                                                     &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
 &lt;BR /&gt;
#    Variable    Type    Len&lt;BR /&gt;
&lt;BR /&gt;
2    chardate    Char      8&lt;BR /&gt;
1    datevar     Num       8&lt;BR /&gt;
  &lt;BR /&gt;
***************************************************&lt;BR /&gt;
  &lt;BR /&gt;
 2) No format -- see internal value&lt;BR /&gt;
&lt;BR /&gt;
Obs    datevar    chardate&lt;BR /&gt;
&lt;BR /&gt;
 1       16106    2/5/04  &lt;BR /&gt;
 2       17130    11/25/06&lt;BR /&gt;
 3       15842    5/17/03 &lt;BR /&gt;
 4       -3334    11/15/50&lt;BR /&gt;
  &lt;BR /&gt;
***************************************************&lt;BR /&gt;
  &lt;BR /&gt;
 3) MMDDYY8 format&lt;BR /&gt;
&lt;BR /&gt;
Obs     datevar    chardate&lt;BR /&gt;
&lt;BR /&gt;
 1     02/05/04    2/5/04  &lt;BR /&gt;
 2     11/25/06    11/25/06&lt;BR /&gt;
 3     05/17/03    5/17/03 &lt;BR /&gt;
 4     11/15/50    11/15/50&lt;BR /&gt;
  &lt;BR /&gt;
***************************************************&lt;BR /&gt;
  &lt;BR /&gt;
 4) Is NEWDATE variable character or numeric&lt;BR /&gt;
&lt;BR /&gt;
The CONTENTS Procedure&lt;BR /&gt;
&lt;BR /&gt;
Data Set Name        WORK.FIXDATE                            Observations          4 &lt;BR /&gt;
Member Type          DATA                                    Variables             3 &lt;BR /&gt;
Engine               V9                                      Indexes               0 &lt;BR /&gt;
Created              Thursday, March 20, 2008 11:22:45 AM    Observation Length    24&lt;BR /&gt;
Last Modified        Thursday, March 20, 2008 11:22:45 AM    Deleted Observations  0 &lt;BR /&gt;
Protection                                                   Compressed            NO&lt;BR /&gt;
Data Set Type                                                Sorted                NO&lt;BR /&gt;
Label                                                                                &lt;BR /&gt;
Data Representation  WINDOWS_32                                                      &lt;BR /&gt;
Encoding             wlatin1  Western (Windows)                                      &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
                                    Engine/Host Dependent Information&lt;BR /&gt;
&lt;BR /&gt;
Data Set Page Size          4096                                                                         &lt;BR /&gt;
Number of Data Set Pages    1                                                                            &lt;BR /&gt;
First Data Page             1                                                                            &lt;BR /&gt;
Max Obs per Page            168                                                                          &lt;BR /&gt;
Obs in First Data Page      4                                                                            &lt;BR /&gt;
Number of Data Set Repairs  0                                                                            &lt;BR /&gt;
File Name                   C:\DOCUME~1\sasczz\LOCALS~1\Temp\SAS Temporary Files\_TD2592\fixdate.sas7bdat&lt;BR /&gt;
Release Created             9.0101M3                                                                     &lt;BR /&gt;
Host Created                XP_PRO                                                                       &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Alphabetic List of Variables and Attributes&lt;BR /&gt;
 &lt;BR /&gt;
#    Variable    Type    Len&lt;BR /&gt;
&lt;BR /&gt;
2    chardate    Char      8&lt;BR /&gt;
1    datevar     Num       8&lt;BR /&gt;
3    newdate     Num       8&lt;BR /&gt;
  &lt;BR /&gt;
***************************************************&lt;BR /&gt;
  &lt;BR /&gt;
 5) CHARDATE variable turned into numeric variable NEWDATE&lt;BR /&gt;
&lt;BR /&gt;
Obs     datevar    chardate     newdate&lt;BR /&gt;
&lt;BR /&gt;
 1     02/05/04    2/5/04      02/05/04&lt;BR /&gt;
 2     11/25/06    11/25/06    11/25/06&lt;BR /&gt;
 3     05/17/03    5/17/03     05/17/03&lt;BR /&gt;
 4     11/15/50    11/15/50    11/15/50&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 20 Mar 2008 17:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/SAS-dates-adding-0-s-in-front-of-numbers-lt-9/m-p/7471#M785</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-03-20T17:34:14Z</dc:date>
    </item>
  </channel>
</rss>

