Solved

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

Posted on 2013-05-13
3
1,981 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 200 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 300 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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