BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zoomzoom
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
esjackso
Quartz | Level 8

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;

View solution in original post

7 REPLIES 7
data_null__
Jade | Level 19

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

zoomzoom
Obsidian | Level 7

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".

esjackso
Quartz | Level 8

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;

zoomzoom
Obsidian | Level 7

Thank you, esjackso1. That was right, the code is working fine.

DBailey
Lapis Lazuli | Level 10

The DTDATE9. format display DDMMMYYYY when applied to a datetime variable.

zoomzoom
Obsidian | Level 7

Thank you, DBailey. Your answer works just fine.

data_null__
Jade | Level 19

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_

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
  • 7 replies
  • 3850 views
  • 6 likes
  • 4 in conversation