Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

807 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