DATA Step, Macro, Functions and more

Date issue

Reply
Super Contributor
Posts: 673

Date issue

I have a date field that has the following formats for dates.
9/1/2009
10/27/09
09/10/2009
I want to covert them all to mm/dd/yyyy format.
I used the followig code:
sh_date1=input(ship_date,anydtdte10.);
format sh_date1 mmddyy10.;
sh_date2=put(sh_date1,mmddyy10.);
drop ship_date sh_date1;
rename sh_date2=ship_date;

The dates that are in the format 09/10/2009 are shown as blank.
How to avoid this?
Super Contributor
Super Contributor
Posts: 3,174

Re: Date issue

Your code worked fine for my test-execution. Suggest you share your SAS log output and add PUTLOG _ALL_; after all assignments are performed in the last DATA step.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 673

Re: Date issue

Sbb,
it works for me too.only that I have to use strip function.
SAS Employee
Posts: 39

Re: Date issue

Here's a small program that works with the sample data and code you provided. I removed the FORMAT statement for sh_date1 since this variable is dropped.

I don't call the STRIP function. If you see blanks where you expect a valid date, it could be that you're working with a missing value, which might result from an invalid date.

[pre]data ship_dates;
length ship_date $ 10;
input ship_date;

sh_date1 = input(ship_date, anydtdte10.);
sh_date2 = put(sh_date1, mmddyy10.);
drop ship_date sh_date1;
rename sh_date2 = ship_date;
datalines;
9/1/2009
10/27/09
09/10/2009
;

proc print data=ship_dates; run;
[/pre]

Output:
[pre]
Obs ship_date

1 09/01/2009
2 10/27/2009
3 09/10/2009
[/pre]
Super Contributor
Posts: 673

Re: Date issue

Posted in reply to JasonS_SAS
Thanks Jason !
Ask a Question
Discussion stats
  • 4 replies
  • 235 views
  • 0 likes
  • 3 in conversation