<?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 partial dates in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60794#M17237</link>
    <description>Hey,&lt;BR /&gt;
&lt;BR /&gt;
can you tell me how i can manage partial dates in SAS? I would like to import a csv-file with a date-variable (the format in the csv-file is like: 10102000 or 1965 or 091922).&lt;BR /&gt;
&lt;BR /&gt;
How can i 'tell' SAS, that 10102000 should have the format ddmmyyyy, 091922 the format mmyyyy and 1965 yyyy?? My idea was to import the variable as character-format and then ask with the length-function for the value-length and make 3 new variables for each format, like:&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate)EQ 8 Then do;&lt;BR /&gt;
test=input(birthdate,ddmmyy10.);&lt;BR /&gt;
format test ddmmyy10.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate)EQ 6 Then do;&lt;BR /&gt;
test2=input(birthdate, mmyy7);	&lt;BR /&gt;
format test2 mmyy7.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate) EQ 4 Then do;&lt;BR /&gt;
test3=input(birthdate,year.);	&lt;BR /&gt;
format test3 year.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
for test everythings works fine but for test2 and test3 not &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; do you have any idea?&lt;BR /&gt;
&lt;BR /&gt;
thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
Marie</description>
    <pubDate>Thu, 05 Aug 2010 08:59:51 GMT</pubDate>
    <dc:creator>marieK</dc:creator>
    <dc:date>2010-08-05T08:59:51Z</dc:date>
    <item>
      <title>partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60794#M17237</link>
      <description>Hey,&lt;BR /&gt;
&lt;BR /&gt;
can you tell me how i can manage partial dates in SAS? I would like to import a csv-file with a date-variable (the format in the csv-file is like: 10102000 or 1965 or 091922).&lt;BR /&gt;
&lt;BR /&gt;
How can i 'tell' SAS, that 10102000 should have the format ddmmyyyy, 091922 the format mmyyyy and 1965 yyyy?? My idea was to import the variable as character-format and then ask with the length-function for the value-length and make 3 new variables for each format, like:&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate)EQ 8 Then do;&lt;BR /&gt;
test=input(birthdate,ddmmyy10.);&lt;BR /&gt;
format test ddmmyy10.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate)EQ 6 Then do;&lt;BR /&gt;
test2=input(birthdate, mmyy7);	&lt;BR /&gt;
format test2 mmyy7.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
if length(birthdate) EQ 4 Then do;&lt;BR /&gt;
test3=input(birthdate,year.);	&lt;BR /&gt;
format test3 year.;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
for test everythings works fine but for test2 and test3 not &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; do you have any idea?&lt;BR /&gt;
&lt;BR /&gt;
thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
Marie</description>
      <pubDate>Thu, 05 Aug 2010 08:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60794#M17237</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2010-08-05T08:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60795#M17238</link>
      <description>When possible, it's best to consider appending character constants to make up the missing component, when converting data-strings to SAS DATE variables.   Have a look at the ANYDTDTE INFORMAT, however that can potentially yield undesirable date values.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
37   data _null_;&lt;BR /&gt;
38   yyyy = '1965';&lt;BR /&gt;
39   dt = input('0101'!!yyyy,ddmmyy8.);&lt;BR /&gt;
40   put dt= date9.;&lt;BR /&gt;
41   run;&lt;BR /&gt;
&lt;BR /&gt;
dt=01JAN1965&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds</description>
      <pubDate>Thu, 05 Aug 2010 09:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60795#M17238</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-05T09:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60796#M17239</link>
      <description>thank you, yes i think i have to do it like that... &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
do you have also an idea how i can code 06.06.6666 and 07.07.7777 as special missing?</description>
      <pubDate>Thu, 05 Aug 2010 10:06:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60796#M17239</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2010-08-05T10:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60797#M17240</link>
      <description>I really don't use "special missing" assignment.  If an assignment statement (using the INPUT function you show with a date) yields a missing value, then you have an invalid formatted date string, and then you can take some action -- suggest reviewing the SAS DOC and the SAS support website.  Always reset _ERROR_=0;  when you have this condition.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
+"special missing" site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
input function "_error_" site:sas.com</description>
      <pubDate>Thu, 05 Aug 2010 10:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60797#M17240</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-05T10:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60798#M17241</link>
      <description>Hi Marie&lt;BR /&gt;
&lt;BR /&gt;
The code below creates a variable containing a SAS date.&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  datestring='10102000';&lt;BR /&gt;
  output;&lt;BR /&gt;
  datestring='091922';&lt;BR /&gt;
  output;&lt;BR /&gt;
  datestring='1965';&lt;BR /&gt;
  output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  SASDateVar=input(datestring,?? ddmmyy8.);&lt;BR /&gt;
  if missing(SASDateVar) then SASDateVar=input(cats('01',datestring),?? ddmmyy8.);&lt;BR /&gt;
  if missing(SASDateVar) then SASDateVar=input(cats('0101',datestring),?? ddmmyy8.);&lt;BR /&gt;
  put SASDateVar= date9.;&lt;BR /&gt;
  SASDateVarAligned=intnx('year',SASDateVar,0,'B');&lt;BR /&gt;
  put SASDateVarAligned= date9.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 05 Aug 2010 10:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60798#M17241</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-08-05T10:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60799#M17242</link>
      <description>please remove partial post

Message was edited by: Peter.C</description>
      <pubDate>Fri, 06 Aug 2010 14:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60799#M17242</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-06T14:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: partial dates</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60800#M17243</link>
      <description>to define your own special-missings, use &lt;BR /&gt;
PROC FORMAT ;&lt;BR /&gt;
    invalue my_mis &lt;BR /&gt;
      '06.06.6666' = .D /*almost number of the be... */&lt;BR /&gt;
      '07.07.7777' = .S &lt;BR /&gt;
        other =[ anydtdte. ]&lt;BR /&gt;
     ;&lt;BR /&gt;
run ;&lt;BR /&gt;
Then use the informat MY_MIS. instead of ANYDTDTE.</description>
      <pubDate>Fri, 06 Aug 2010 14:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/partial-dates/m-p/60800#M17243</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-06T14:23:50Z</dc:date>
    </item>
  </channel>
</rss>

