DATA Step, Macro, Functions and more

how to convert date in a macro into character

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

how to convert date in a macro into character

I am trying to convert the date variable in a macro into a character variable called "label".

 

%let date=%qsysfunc(intnx(month, '31Oct2017'd, 2));


But the following gives errors. Any idea how to achieve this?

 

%let label=%sysfunc(put(&date, date9.));

ERROR: The PUT function referenced in the %SYSFUNC or %QSYSFUNC macro function is not found.


Accepted Solutions
Solution
‎10-10-2017 10:16 AM
Super User
Posts: 7,846

Re: how to convert date in a macro into character

The put() function is one of those that are not available in %sysfunc and %qsysfunc.

See here: http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=mcrolref&docsetTarget=p1o1...

Use the putn() function instead:

%let date=%sysfunc(intnx(month, '31Oct2017'd, 2));

%let label=%sysfunc(putn(&date,date9.));
%put &label;

or do it in one step:

%let label=%sysfunc(intnx(month, '31Oct2017'd, 2),date9.);

%put &label;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 5,516

Re: how to convert date in a macro into character

%SYSFUNC cannot be used with PUT.  You have to switch to PUTN (in this case) or PUTC (in some cases) instead.

Solution
‎10-10-2017 10:16 AM
Super User
Posts: 7,846

Re: how to convert date in a macro into character

The put() function is one of those that are not available in %sysfunc and %qsysfunc.

See here: http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=mcrolref&docsetTarget=p1o1...

Use the putn() function instead:

%let date=%sysfunc(intnx(month, '31Oct2017'd, 2));

%let label=%sysfunc(putn(&date,date9.));
%put &label;

or do it in one step:

%let label=%sysfunc(intnx(month, '31Oct2017'd, 2),date9.);

%put &label;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 93 views
  • 0 likes
  • 3 in conversation