I am facing a difficulty whereby I couldn't find a way to read the source character values to determine if it is a date format (possible in YYYYMMDD and MMDDYYYY) or other character format such as car_0001.
Sample as below.
data test;
value1='19990131';
value2='12312006';
value3='car_0001';
value4='blue_001';
run;
As we can see from above, each columns have its own value.
Is there a way that I can identify value 1 as YYYYMMDD, value 2 as MMDDYYYY, or value 3 and 4 as character (nondate)?
I couldn't think of a function to do so.
data test;
value='19990131'; output;
value='12312006'; output;
value='car_0001'; output;
value='blue_001'; output;
run;
data want;
set test;
date=input(value,anydtdte.);
run;
If the value of DATE is missing, then it is not recognized as a SAS date. This method, using informat ANYDTDTE, is not perfect, it won't give you the proper answer 100% of the time.
data test;
value='19990131'; output;
value='12312006'; output;
value='car_0001'; output;
value='blue_001'; output;
run;
data want;
set test;
date=input(value,anydtdte.);
run;
If the value of DATE is missing, then it is not recognized as a SAS date. This method, using informat ANYDTDTE, is not perfect, it won't give you the proper answer 100% of the time.
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.