Help using Base SAS procedures

Changing date format from YYMM7. to MMDDYY10.

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Changing date format from YYMM7. to MMDDYY10.

I have a SAS dataset with a variable named cars in YYMM7. format and I want to convert it to MMDDYY10. format. Please suggest the complete code to do so. This is what i have so far-


%let path=C:\Users\AB\Documents\My SAS Files\9.4; 
libname abcd "&path";
ods HTML file="C:\Users\AB\Documents\My SAS Files\9.4\line.xls";
proc print data=abcd.line;
run;
ods HTML close;

 

I am using a sas dataset to create an excel file and I need the date of the variable cars changed from YYMM7. to MMDDYY10. format.

 


Accepted Solutions
Solution
‎08-18-2017 02:52 PM
Super User
Posts: 23,747

Re: Changing date format from YYMM7. to MMDDYY10.

[ Edited ]

You shouldn't use ODS HTML to create an Excel file, unless you're on really old versions of SAS IMO.

 

%let path=C:\Users\AB\Documents\My SAS Files\9.4; 

libname abcd "&path";

ods Excel file="C:\Users\AB\Documents\My SAS Files\9.4\line.xlsx";

proc print data=abcd.line;

format cars mmddyy10.;
run; ods excel close;

View solution in original post


All Replies
Super User
Posts: 10,259

Re: Changing date format from YYMM7. to MMDDYY10.

Post example data, in a data step so we can see the variable attributes. From your post, it is not clear if you have a SAS date variable or a string.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 24

Re: Changing date format from YYMM7. to MMDDYY10.

Posted in reply to KurtBremser
2017M06
2015M10
2014M06
2014M03
2014M03
2014M06

above is an example of the various observations in the variable  that I want to change to the following format-

7/1/2012
10/1/2013
10/1/2013
10/1/2012
4/1/2012
Solution
‎08-18-2017 02:52 PM
Super User
Posts: 23,747

Re: Changing date format from YYMM7. to MMDDYY10.

[ Edited ]

You shouldn't use ODS HTML to create an Excel file, unless you're on really old versions of SAS IMO.

 

%let path=C:\Users\AB\Documents\My SAS Files\9.4; 

libname abcd "&path";

ods Excel file="C:\Users\AB\Documents\My SAS Files\9.4\line.xlsx";

proc print data=abcd.line;

format cars mmddyy10.;
run; ods excel close;
Contributor
Posts: 24

Re: Changing date format from YYMM7. to MMDDYY10.

what do you suggest for creating an excel file from SAS dataset?

Super User
Posts: 23,747

Re: Changing date format from YYMM7. to MMDDYY10.

Proc export or ODS EXCEL. I even wrote the code for one of those...

Contributor
Posts: 24

Re: Changing date format from YYMM7. to MMDDYY10.

Thank you so much Reeza! Smiley Happy

 

Contributor
Posts: 24

Re: Changing date format from YYMM7. to MMDDYY10.

what is the code for proc export?
Super User
Posts: 23,747

Re: Changing date format from YYMM7. to MMDDYY10.

Here's an old blog post that has sample code and several methods.

http://blogs.sas.com/content/sasdummy/2012/02/11/export-excel-methods/

 

Contributor
Posts: 24

Re: Changing date format from YYMM7. to MMDDYY10.

Thanks Reeza! Incredibly helpful!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 515 views
  • 0 likes
  • 3 in conversation