- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello members,
I'm a new member joined. I know the question I'm going to ask might have been asked n number of times. But so far I'm unable to fix the problem.
Problem:
I'm trying to convert SAS Date in DHMS format to SAS Date Date9 format. The date came in from SQL server and in DDMMMYYYY:00:00:00.000 format.
The date I have is 10JAN2011. I have converted to numeric and to character and I get the value 18637 in character format. But then, I'm unable to convert to date9 format. All I get is missing values with error message as "Invalid argument to function Input". I also tried with sasdatefmt in standard syntax, but the code is not working
Code :
data want;
set have;
dt= input(put(datepart(Date),5.),ddmmyy10.);
format dt Date9.;
run;
Thank you.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not sure its clear what you are trying to do.
If all you need is the date to show as 10Jan2011 then you do not need to use the put function (just the datepart) and just associate the format with the variable. If you are converting to a character variable then I think you need to just replace the 5. format in the put with the date9. format.
EJ
EDIT:
Sample code to illustrate
data temp;
x = 18637;
format x date9.;
x2= put(x,date9.);
y='10Jan2011 12:00:00'dt;
y2 = datepart(y);
format y2 date9.;
y3 = put(y2,date9.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
18637 is 10Jan2011 nothing else to do except associate a format.
17 data _null_;
18 x = 18637;
19 put x=date9.;
20 run;
x=10JAN2011
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
So I have modified the code to:
data want;
set have;
dt= put(datepart(Date),5.);
format dt date9.;
run;
But the error exits. The log says:
"Note 484-185: Format $Date was not found or could not be loaded".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not sure its clear what you are trying to do.
If all you need is the date to show as 10Jan2011 then you do not need to use the put function (just the datepart) and just associate the format with the variable. If you are converting to a character variable then I think you need to just replace the 5. format in the put with the date9. format.
EJ
EDIT:
Sample code to illustrate
data temp;
x = 18637;
format x date9.;
x2= put(x,date9.);
y='10Jan2011 12:00:00'dt;
y2 = datepart(y);
format y2 date9.;
y3 = put(y2,date9.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, esjackso1. That was right, the code is working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The DTDATE9. format display DDMMMYYYY when applied to a datetime variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, DBailey. Your answer works just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The date I have is 10JAN2011. I have converted to numeric and to character and I get the value 18637 in character format.
Do NOT convert to character. When you get the NUMBER 18637 you are done. All you need after that is to associate a date format.
Message was edited by: data _null_