BookmarkSubscribeRSS Feed
Helannivas
Quartz | Level 8

I have some source columns like(For Eg.)

Process_Date

Jun 01 2013 6.40pm

Feb 14 2012 7.25am

Mar 28 2011 3.40pm

I need to validate this column,whether tis date is correct date or not.

Then,I need to load this date column to target as (DD/MM/YYYY). like

01/06/2013

14/02/2012

28/03/2011

How to do this in SAS DI Studio?Kindly help me on this.

5 REPLIES 5
sunilzood
Calcite | Level 5

Hi Helann,

Please try ....

data have ;
input test_date $20. ;
cards;
Jun 01 2013 6.40pm
Feb 14 2012 7.25am
Mar 28 2011 3.40pm
;run;

data want (drop = a b c d) ;
set have;
a = compress(upcase(substr(test_date,1,3)));
b = substr(test_date,5,2);
c = substr(test_date,8,4);
  if a = 'JAN' then d = 1;
else if a = 'FEB' then d = 2;
else if a = 'MAR' then d = 3;
else if a = 'APR' then d = 4;
else if a = 'MAY' then d = 5;
else if a = 'JUN' then d = 6;
else if a = 'JUL' then d = 7;
else if a = 'AUG' then d = 8;
else if a = 'SEP' then d = 9;
else if a = 'OCT' then d = 10;
else if a = 'NOV' then d = 11;
else if a = 'DEC' then d = 12;
Final_date  = mdy(d,b,c);
format Final_date ddmmyy10.;
Run;

Ksharp
Super User
data have ;
input test_date & ?? anydtdtm. ;
date=datepart(test_date);
format date ddmmyy.;
cards;
Jun 01 2013 6.40pm
Feb 14 2012 7.25am
Mar 28 2011 3.40pm
;run;

Ksharp

sunilzood
Calcite | Level 5

Good one Shap, I was expecting for a best Solution... Thanks.!!

Patrick
Opal | Level 21

Assuming you start with an external file then you could define the Process_Date column with informat "anydtdte." and format "ddmmyy10." in the "external file" object.

Then use a "File Reader" and then a "Data Validation" transformation.

In the "Data Validation" transformation check for missings. All source values for "Process_Date" (the text strings) which couldn't be converted to a SAS date value will be missing.

Helannivas
Quartz | Level 8

Thanks all for ur reply.

I am facing an issue in all client machines.So I cant able to run any job.

I will try tis ,once the issue is resolved.

Can u  pls help me in resolving this issue.

https://communities.sas.com/thread/47658

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 2325 views
  • 0 likes
  • 4 in conversation