how to convert date wich is in MM/DD/YYYY to YYYYMMDD in enterprise SAS on unix platform

raniravs
raniravs used Ask the Experts™
on
Hi,
   Here is my data set by name "file1.sas7b.dat"

                  Patient ID           DOB
1.              2SRE3456            01/12/2014
2.              S456HRW             1/2/2014
3.              GT567575            02/01/2014

Here is my SAS Enterprise program to convert DOB to YYYYMMDD. But it is not working... ANy help will be greatly appreciated

Data file2_YYYYMMDD;
   set file1;
New_Date = Input(TRIM(DOB),MMDDYY10.);
Run;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Statistician
Commented:
Hi there

The variable  DOB  in your sas data set may be either

A numeric variable being stored as the number of days since the date origin and displayed using an associated format probably  mmddyy10.

or

A character variable of length at least 10 that contains the characters   "0" and "1" and "/" and "1" and "2" and "/" and "2" and "0" and "1" and "4".

In the first case all you need to do is change the format as in

data file2_YYYYMMDD;
   set file1;
   format DOB yyyymmdd.;
run; 

Open in new window


In the second case your code will work except you will need to provide a format for New_Date similar to above.

...

run proc contents on the file is an easy way to find out which case you have.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial