Help using Base SAS procedures

Get month from a date format

Reply
Super Contributor
Posts: 395

Get month from a date format

Hi, I havea data format as such MMDDYYP10. (samples below), I'm trying to get the months out of the dat but in a MONNAME. format.

Have

Date

05.02.2012

06.14.2012

07.04.2012

I used

Date_A = Month (Date);

Format Date_A MONANME.  but this didn't quite work

Want

Date_B   

May 

June

July

Super User
Posts: 17,784

Re: Get month from a date format

The monname format uses a date variable not a month variable.

so

date_a=date;

format date_a monname10.;

or

format date monname10.;

Super Contributor
Posts: 395

Re: Get month from a date format

Thank you

Super Contributor
Posts: 395

Re: Get month from a date format

Hi Reeza, when I export it to Excel the date_a doesn't come across as only Month , but as the whole date similar to date.  In SAS it shows correct, how I would like it to.

Super User
Posts: 17,784

Re: Get month from a date format

You exported the data with proc export?

By definition SAS does not export formats to Excel using proc export.

Instead you can create a new variable using the put statement that will recode the data and then export.

data_a=put(date, monname10.);

Super Contributor
Posts: 543

Re: Get month from a date format

Hi.

PROC EXPORT does not keep formats, but the ODS tagsets does.

Below is a sample code that will keep ALL your formats.

       ods listing close;
             ods tagsets.excelxp path = "&output_path." file="&data..xml"
             style=analysis      options(absolute_column_width='10,10,8,8,10,10,15,8,15,8,15,10,8,8,8,8,10,10,15,8,15,8,15,10,8,8,8,8,20' 
        sheet_label=' ');


        ods tagsets.excelxp options(sheet_name="sheetname");

             proc print noobs label data = &data.;
                 var your_variables;
             run;
        ods tagsets.excelxp close;
        ods listing;

Good luck!

Ask a Question
Discussion stats
  • 5 replies
  • 294 views
  • 4 likes
  • 3 in conversation