DATA Step, Macro, Functions and more

Convert numeric month to "mmm" string and use as filename

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Convert numeric month to "mmm" string and use as filename

Hello,

I am trying to convert the pmons(numeric month)to monname3. month.

 

%let pmons = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(date()),-1))));

ods tagsets.ExcelXP file="C:\Reports\TEST_ME_&pmons&cyear..xls" style=sasweb

options(absolute_column_width='6,20,4');

PROC REPORT DATA=ME nowd;

column ID NAME CODE;

define ID / style(column)={tagattr='00000'};

 

My file name should be: TEST_ME_MAY2018.xls

 

Thank you.


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 13,507

Re: Convert numeric month to "mmm" string and use as filename

Since you have date value PUT it with the appropriate format:

 

%let pmons= %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(date()),-1)),monname3.));

%put &pmons;

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 13,507

Re: Convert numeric month to "mmm" string and use as filename

Since you have date value PUT it with the appropriate format:

 

%let pmons= %sysfunc(putn(%sysfunc(intnx(month,%sysfunc(date()),-1)),monname3.));

%put &pmons;

Contributor
Posts: 51

Re: Convert numeric month to "mmm" string and use as filename

Thank you Ballardw. It's work!
Super User
Posts: 23,677

Re: Convert numeric month to "mmm" string and use as filename

[ Edited ]

The second parameter in the %SYSFUNC() is a format. 

 

%let pmons= %sysfunc(intnx(month,%sysfunc(date()),-1),monname3.);

%put &pmons;

Use SYSFUNC() once for the date() function and once for the INTNX and then apply the format. The format MONNAME3 works off a SAS date, not a month. So if MONTH() is applied, it returns a number from 1 to 12 but there is not a format to convert a value of 1 to 12 to a month name. You could create your own if desired. 

 

Note that you can get the full value, May2018 in a single macro variable as well:

 

%let pmons= %sysfunc(intnx(month,%sysfunc(date()),-1),monname3.);

%put &pmons;

 


@BonnaryW wrote:

Hello,

I am trying to convert the pmons(numeric month)to monname3. month.

 

%let pmons = %sysfunc(month(%sysfunc(intnx(month,%sysfunc(date()),-1))));

ods tagsets.ExcelXP file="C:\Reports\TEST_ME_&pmons&cyear..xls" style=sasweb

options(absolute_column_width='6,20,4');

PROC REPORT DATA=ME nowd;

column ID NAME CODE;

define ID / style(column)={tagattr='00000'};

 

My file name should be: TEST_ME_MAY2018.xls

 

Thank you.


 

Contributor
Posts: 51

Re: Convert numeric month to "mmm" string and use as filename

Thank you Reeza. It's work !!!
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 66 views
  • 2 likes
  • 3 in conversation