Hi, I have a text file with a date with multiple date formats. Kind of what's created below in the sample data. I also created a picture format for the date format I need (further below). What I can't figure out is how to conditionally read in the file and maintain the data as a date. The final output needs to have the new date format (newdate.). I'm trying to avoid reading it in as a string then converting it later. Any ideas?
Thanks!
*sample data;
data test;
input date $10.;
datalines;
01JUL2020
2020-07-01
;
run;
*new data format.
proc format;
picture NewDate other='%Y-%0m-%0d' (datatype=date);
run;
%let now=%sysfunc(today(),newdate.);
%put &now;
No need for custom formats:
data test;
input date anydtdte10.;
format date yymmddd10.;
datalines;
01JUL2020
2020-07-01
;
Although I would rather have (preferred in this order):
No need for custom formats:
data test;
input date anydtdte10.;
format date yymmddd10.;
datalines;
01JUL2020
2020-07-01
;
Although I would rather have (preferred in this order):
If you have two-digit years in the first position they may be treated as dd-mm-yy instead of yy-mm-dd values OR mm-dd-yy, national language rules, and may have missing values using the ANYDTDTE infromat.
So double check any results with 2 digit years, if any, from your source file, and the range of result for sensibility. If you end up asking "how did that date get in there" these are candidates for odd values in your input and the coding rules for ANYDTDTE
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.