BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
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?
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
SASPhile
Quartz | Level 8
Sbb,
it works for me too.only that I have to use strip function.
JasonS_SAS
SAS Employee
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]
SASPhile
Quartz | Level 8
Thanks Jason !

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1854 views
  • 0 likes
  • 3 in conversation