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

I have a character column called BIRTH_DT, where all the values are stored as DDMMYY.

Example values:

"240578"

"210388"

"321284"

"010295"

"300594"

I want to extract all the values that aren't stored in a correct date format/syntax. So for example, the value "321284" would be extracted.

I could just do a substring of the first two sets of numbers and check that the day is between 01-31, and the month between 01-12, but that would a cheap solution with plenty of room for error.

Although this kind of date quality validation must be an incredibly frequent thing to do, it's surprisingly hard to find any good advice about it on Google. Perhaps I'm not a particularly good Googler. Any advice would be appreciated, thanks. Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Generally in SAS we recommend using SAS date variables instead of character.

if you do something like this in a datastep:

testdate= input(birth_dt, ddmmyy.);

if testdate=. then put "BIRTH_DT of " birth_dt "not valid for " <record identfying variables>;

Any values that are not valid for your format will result in a missing value of Testdate and the IF statement will write to the log any associated information if you add other variables.


View solution in original post

1 REPLY 1
ballardw
Super User

Generally in SAS we recommend using SAS date variables instead of character.

if you do something like this in a datastep:

testdate= input(birth_dt, ddmmyy.);

if testdate=. then put "BIRTH_DT of " birth_dt "not valid for " <record identfying variables>;

Any values that are not valid for your format will result in a missing value of Testdate and the IF statement will write to the log any associated information if you add other variables.


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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