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

I suppose there is an easy fix for this, although I am new to SAS so it seems a little tricky at the moment.

Basically I have a date variable that is in character format ( $ 10) and looks like 06/31/2009, as an example. I would like to get that to date9. format if possible.

Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
Fugue
Quartz | Level 8

Editor's Note:  Thanks to Fugue for providing an example of how to use the INPUT function to convert a character date into a SAS date and then using the FORMAT statement to apply the desired format.

 

 

Try this:

Data want;
set have;
format datevar date9.;
datevar = input ( chardate, MMDDYY10.);
run;

 

 

View solution in original post

5 REPLIES 5
Fugue
Quartz | Level 8

Editor's Note:  Thanks to Fugue for providing an example of how to use the INPUT function to convert a character date into a SAS date and then using the FORMAT statement to apply the desired format.

 

 

Try this:

Data want;
set have;
format datevar date9.;
datevar = input ( chardate, MMDDYY10.);
run;

 

 

Hudson33
Calcite | Level 5

Thanks very much! Would the same be the case for changing DATE9. to the numeric SAS date?

Thanks again!

Fugue
Quartz | Level 8

SAS date and time values are stored as numbers, but displayed according to the chosen format. Example:

Data want;

set have;

format formatted_date date9. /* displays stored date value with specified format */

     not_formatted_date best. /* number format */;

formatted_date = input ( chardate, MMDDYY10.); /* stores value as a SAS date value (number). Format determines which date format is used to display it. */

not_formatted_date = formatted_date; /* also a numeric value, but format displays it as a number */

run;

PaulaC
Fluorite | Level 6
My current character value is stored as ddmmmyyyy so I used date9. when changing it to the numeric value. The problem is that when I look at my data set the value for that variable is the SAS date. I tried using "format dateqol date9.;" to get it into the correct format, but I am getting the following error message: ERROR 48-59: The format $DATE was not found or could not be loaded.
What am I doing wrong? I put the format statement prior to the input statement. Thanks.
P_trivedi
Calcite | Level 5

Dear PaulaC,

 

Refer below code for your mentioned query:

 

data dateC;
input chardate :$9.;
datalines;
31dec1999
;
run;

data dateN;
set dateC;
format sasdate date9.;
sasdate=input(chardate,date9.);
run;

 

Placement of format statement does not affect at all.

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
  • 5 replies
  • 108345 views
  • 3 likes
  • 4 in conversation