How to get current month name and year in SAS using macro

[亡魂溺海] 提交于 2020-11-29 11:49:07

问题


I am triggering a mail in SAS which should holds current month and year in the mail

How can I create macro variables &month &yearsuch that

  • &month should display October
  • &year should display 2020

Currently using

%let sysmonth= %sysfunc(month("&sysdate"d));
%let sysyear= %sysfunc(year("&sysdate"d));

%put &sysmonth &sysyear;

But I am getting month in number but i want the month in words


回答1:


Use PUTN with format MONNAME

%put %sysfunc(PUTN("&sysdate"d, monname.));
------ LOG ------
October



回答2:


%SYSFUNC has an optional second argument that specifies format. In the particular case here you don't really need it - Richard's PUTN works just as well - but in the case that you do want a function to operate, here's that example - the example here being for if you want a different month than the current one, but any function works this way.

%let sysmonth= %sysfunc(intnx(month,"&sysdate"d,-1),monname.);
%put &=sysmonth;


来源:https://stackoverflow.com/questions/64351082/how-to-get-current-month-name-and-year-in-sas-using-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!