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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1235 views
  • 0 likes
  • 4 in conversation