Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-05-13
3
Medium Priority
?
2,227 Views
Last Modified: 2013-05-14
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
Comment
Question by:morinia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Assisted Solution

by:Aloysius Low
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

by:
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;

Open in new window

0
 

Author Closing Comment

by:morinia
ID: 39164684
Thanks guys.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question