BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
StickyRoll
Fluorite | Level 6

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 673 views
  • 0 likes
  • 2 in conversation