I'm trying to find a way to identify the subset of numeric variables that represent dates, times or datetimes from an arbitrary dataset that contains many variables of both numeric or character type. The goal is to have a macro or template that I could run against any given dataset. I believe that the SAS formats for these variables should correctly represent what the variables are, but I'm trying to see if I can avoid having to create some code that parses the text of the SAS format for any of the applicable format names.
I was originally thinking it should be possible to do something like the following to get the SAS formats for a dataset and then do various things based on the columns that come back as date/time/datetime.
PROC SQL;
CREATE TABLE lib_X.Dataset_A AS
SELECT tbl_CL.LIBNAME
,tbl_CL.MEMNAME AS TABLE_NAME
,tbl_CL.NAME AS COLUMN_NAME
,tbl_CL.FORMAT AS SAS_Format
,tbl_CL.TYPE AS SAS_Type
,tbl_CL.varnum
,tbl_CL.LENGTH
FROM DICTIONARY.COLUMNS AS tbl_CL
WHERE tbl_CL.MEMNAME = %UPCASE("&SAS_DatasetNm")
AND tbl_CL.LIBNAME = %UPCASE("&SAS_LibNm");
QUIT;
Followed by:
DATA lib_X.Dataset_A;
SET lib_X.Dataset_A;
IF FCN_FORMAT_TYPE(SAS_Format) = "DATETIME"
THEN ...;
RUN;
Where the FCN_FORMAT_TYPE
function is some function that examines the SAS format and returns which of the 4 categories of SAS Format (character, numeric, date/time, or ISO 8601) the variable is, but there doesn't seem to be an existing function that does this that I can find. Perhaps there's another approach that would work?
Currently running on SAS 9.4 M2 on a Linux server. The code will primarily be used via batch file, but possibly via Enterprise Guide as well (EG 7.1 or 6.1)