BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

User define 2 macro variables in format YYMM.

The task is to create 2 more macro variables that are calculated automatically.

What is the way to calculate them please?

First macro var will get value of start of month of  From_YYMM

Second macro var will get value of End of month of  until_YYMM

 

/***USer Define macro variables***/
%let From_YYMM=2212;
%let until_YYMM=2307;

/***Macro variables that need to be calculated automatically***/
%let FROM='01DEC2022'd;
%let Until='31JUL2023'd;
1 ACCEPTED SOLUTION
2 REPLIES 2
mkeintz
Jade | Level 19

I'd suggest:

%let from_date=%sysfunc(putn(%sysfunc(inputn(20&from_yymm.01,yymmdd8.)),date9.));
%let until_date=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e)),date9.));

which will produce macrovars

GLOBAL FROM_DATE 01DEC2022
GLOBAL FROM_YYMM 2212
GLOBAL UNTIL_DATE 31JUL2023
GLOBAL UNTIL_YYMM 2307

I think eliminating the single quotes makes things simpler.  FROM_DATE and UNTIL_DATE are human-readable, while allowing this usage in your regular SAS code.  Just use double-quotes (which will not mask the value from the macro interpreter) and the trailing letter d.

 

where date between "&from_date"d and "&to_date"d;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 103 views
  • 2 likes
  • 3 in conversation