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!
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;
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;
Thanks very much! Would the same be the case for changing DATE9. to the numeric SAS date?
Thanks again!
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.