Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now