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 !

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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