DATA Step, Macro, Functions and more

LAST DAY OF MONTH WITH QUOTATION MARK Automation

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

LAST DAY OF MONTH WITH QUOTATION MARK Automation

I want to create one macro for the last date of the month with quotation mark and with D suffix,

'31MAR2016'D
'30JUN2016'D
'30SEP2016'D
'31DEC2016'D
'31MAR2017'D

 I want to create another macro only with quotation mark...like:

 

'31MAR2016'
'30JUN2016'
'30SEP2016'
'31DEC2016'
'31MAR2017'

 

I am trying with this:

%LET

YYQ = %SYSFUNC(INTNX(QTR, %SYSFUNC(TODAY()), -1, E) , DATE9.);

 

But this does not give quotation mark and D suffix

 


Accepted Solutions
Solution
‎08-09-2016 01:58 PM
Super User
Posts: 9,662

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

%LET YYQ =%SYSFUNC(QUOTE( %SYSFUNC(INTNX(QTR, %SYSFUNC(TODAY()), -1, E) , DATE9.)))D;

%put &YYQ ;

View solution in original post


All Replies
Super User
Posts: 5,254

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

If you can live with " instead of ' (because it's easier to handle).
So, since macro variables is just text right off, just add it to right side of the %let statement.
The " will allow the macro function calls evaluate, ' won't.
Data never sleeps
Super User
Super User
Posts: 7,392

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

Why?  Macro language is for generating text, it has no data constructs or data processing functionality.  It would be far better to use Base SAS, datasets and such like for processing data.  If you provide information on what you are trying to do we can provide code.

Respected Advisor
Posts: 3,886

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

What about?

%LET YYQ = "%SYSFUNC(INTNX(QTR, %SYSFUNC(TODAY()), -1, E) , DATE9.)"d;
Super User
Posts: 10,459

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

I would reconsider this entirely, especially for the first part.. The only place that you need "01MAR2016"D or similar would be for date literals. The actual integer values will work just as well. The literal form is so us humans understand what the code is doing instead of trying to make the conversion from 20514.

Such as

%let YYQ = %SYSFUNC(INTNX(QTR, %SYSFUNC(TODAY()), -1, E));


data _null_;
   x=&yyq;
   put "The target date is" +1 x date9.;
run;

 

 

Any place you would then need '30Mar2016' would very likey work with put(&macrovar,date9.)  <Note: no quote for integer looking text from above.

 

My experience with putting quotes into SAS macro variables is that it almost never works well in the long run or I spend way too much time getting the logic to work, especially for complex code with many variables.

Solution
‎08-09-2016 01:58 PM
Super User
Posts: 9,662

Re: LAST DAY OF MONTH WITH QUOTATION MARK Automation

%LET YYQ =%SYSFUNC(QUOTE( %SYSFUNC(INTNX(QTR, %SYSFUNC(TODAY()), -1, E) , DATE9.)))D;

%put &YYQ ;

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 286 views
  • 4 likes
  • 6 in conversation