Hi
how can I convert this text to a date I can use in SAS.?
April 1, 2016
currently stored as CHAR $18
thanks
data want;
set have;
Sasdate = input(textdate, anydtdte32.);
format Sasdate mmddyy10.;
run;
Typically:
sas_date = input(string_date, worddate18.);
Then apply a format to SAS_DATE such as:
format sas_date yymmdd10.;
or
format sas_date date9.;
Thanks for the response but im getting the following error...
sas_date = input(date, worddate18.);
-----------
48
ERROR 48-59: The informat WORDDATE was not found or could not be loaded
Usually there's an informat for the date, but this doesn't have an informat that I could find.
You can create it into a date format that SAS will recognize, I used Date9. format, since it's the most common in SAS.
I use the SUBSTR, SCANx2 function to extract the month, day and year, respectively, and the CATT to concatenate them together.
data have;
informat date_char $20.;
input date_char $20.;
cards;
April 1, 2016
December 24, 2016
April 30, 2015
May 18, 2014
November 1, 2012
February 28, 2016
;
run;
data want;
set have;
date_format9 = catt(put(input(scan(date_char, 2), 2.), z2.),
substr(date_char, 1, 3),
scan(date_char, 3)
);
date_num = input(date_format9, date9.);
format date_num date9.;
run;
You guys are right! There's a WORDDATE18 format, but not a WORDDATE18 informat.
Reeza's idea looks good. I might simplify one part:
date_format9 = cats( scan(date_char, 2, ' ,'), substr(date_char, 1, 3), scan(date_char, 3) );
Note that both blanks and commas are being used as delimiters in the first SCAN function.
data want;
set have;
Sasdate = input(textdate, anydtdte32.);
format Sasdate mmddyy10.;
run;
@ballardw Interesting. I tried with ANYDTDTE but didn't specify a width, and that didn't work. I forgot there's a default width 🙂
Hi there,
Is there a similar solution to extract the time from this text var format $25.
12:30PM:Friday:Weekday
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.