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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.