infile date 00/00/00

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

infile date 00/00/00

hi all,

 

try to infile a list of date and by default it was set to 00/00/00, when i execute 00/00/00 will become missing value as it is a invalid date. Can it extract as a date 00/00/00 instead of missing value?

 

data testing;
  infile datalines dlm='|';
  input h :ddmmyy. g :ddmmyy.;
  format h g ddmmyy8.;
datalines;
10/12/07    | 10/01/16
00/00/00    | 28/03/17

;

 

please advice.


Accepted Solutions
Solution
‎03-27-2017 02:41 PM
Super User
Posts: 6,357

Re: infile date 00/00/00

You can't save 00/00/00 as a date, because it isn't a date.  However, you can create your own format for display purposes.  For example:

 

proc format;

value mydate .='00/00/00' other=[ddmmyy8.];

run;

 

Then when using the data, apply the format:

 

format h g mydate.;

 

Just one final word, though.  After the billions of dollars spent overcoming problems with two-digit years, why wouldn't you choose a format that permits four-digit years?

View solution in original post


All Replies
Super User
Posts: 12,676

Re: infile date 00/00/00

What date do you want to use instead of missing? No day of the month, no month of the year = not a date. So the value cannot be represented as a date.

 

What will you do with those date variables later on?

Contributor
Posts: 60

Re: infile date 00/00/00

thank for your time ballardw,

actually the date was recorded as an incident happen, eg payment date, transaction date etc. if 00/00/00 means no transaction or payment was made.

Best Regards
Contributor
Posts: 60

Re: infile date 00/00/00

Possible to put it as 00/00/00 string since 00/00/00 is not a valid date?
Valued Guide
Posts: 505

Re: infile date 00/00/00


proc format;
 invalue fmtdte
  '00/00/00' =-9E99
   other = [ddmmyy.]
;
run;quit;

data testing;
  informat h fmtdte.;
  input h ;
cards4;
10/12/07
00/00/00
;;;;
run;quit;


Up to 40 obs WORK.TESTING total obs=2

Obs          H

 1       17510
 2       -9E99


or


Up to 40 obs WORK.TESTING total obs=2

Obs        H

 1     17510
 2         0



Super User
Posts: 12,676

Re: infile date 00/00/00

Posted in reply to rogerjdeangelis

@rogerjdeangelis

 

I think that an Informat/ Format solution may work better with the special missing

 

proc format;

invalue fmtdte

   '00/00/00'= .A

   other =[ddmmyy8.];

value mydate

   .A='00/00/00'

   other=[ddmmyy8.];

run;

 

Use of any value may run into issues with date functions.

  

Solution
‎03-27-2017 02:41 PM
Super User
Posts: 6,357

Re: infile date 00/00/00

You can't save 00/00/00 as a date, because it isn't a date.  However, you can create your own format for display purposes.  For example:

 

proc format;

value mydate .='00/00/00' other=[ddmmyy8.];

run;

 

Then when using the data, apply the format:

 

format h g mydate.;

 

Just one final word, though.  After the billions of dollars spent overcoming problems with two-digit years, why wouldn't you choose a format that permits four-digit years?

Contributor
Posts: 60

Re: infile date 00/00/00

Posted in reply to Astounding
Thank you so much Astounding,
for your question, just wanted to import to SAS according to the original text format. Or maybe in future, it might change to four-digit years.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 198 views
  • 0 likes
  • 4 in conversation