[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Coverting data from CYYMMDD to MM/DD/YYYY in SAS

Posted on 2013-05-13
Medium Priority
2,288 Views
Is there a way in SAS to convert the date below from  in SAS

Century Year Month Day  = CYYMMDD    2050527

I would like to convert to MM/DD/YYYY   05/27/2005
0
Question by:morinia

LVL 14

Assisted Solution

Aloysius Low earned 800 total points
ID: 39163416
the only way i see this happening is to strip off the first character then converting into a SAS date using the YYMMDD6. informat

data date;
date_str = "2050527";
date = input(substr(date_str, 2), yymmdd6.);
/* if you wish to store the converted value as a SAS date displayed as mm/dd/yyyy */
format date mmddyys10.;
/* if you wish to store the converted value as a character displayed as mm/dd/yyyy */
new_date_str = put(date, mmddyys10.);
run;

however, doing so years that are between 0 and 19 becomes 2000 to 2019, and 20 to 99 becomes 1920 to 1999

would this suffice?
0

LVL 11

Accepted Solution

theartfuldazzler earned 1200 total points
ID: 39163686
Hi

Just to enhance Iowa's code - you can insert an IF-THEN statement to check the first letter:

``````data date;
date_str = "1050527";
IF date_str = : "2" then date_str2 = "20"||SUBSTR(date_str,2);
ELSE date_str2 = "19"||SUBSTR(date_str,2);

date = input(date_str2, yymmdd8.);
/* if you wish to store the converted value as a SAS date displayed as mm/dd/yyyy */
format date mmddyys10.;
/* if you wish to store the converted value as a character displayed as mm/dd/yyyy */
new_date_str = put(date, mmddyys10.);
run;
``````
0

Author Closing Comment

ID: 39164684
Thanks guys.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month17 days, 14 hours left to enroll