Solved

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

Posted on 2013-05-13
3
1,804 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now