I am creating a macro variable for dates such that
%let change_date= '2018-07-01'
%put &change_date
%let interval = 15 (or 30 or 45)
and it should give me a macro variable with dates
%let previous_end_date = '2018-06-30' (This is change_date -1)
%let previous_start_date= '2018-06-16' (this is change_date -15)
%let current_start_date= '2018-07-02' (This is change_date+1)
%let current_end_date= '2018-07-16' (This is change_date+15)
I want the dates to be in this format as this is how Teradata accept the date values. Can you help me out on how to do this macro's calculation?
Any help is highly appreciated.
Use CALL SYMPUT logic to read the date values into macro variables like this
data _null_;
change_date= '01jul2018'd;
previous_end_date=change_date-1;
previous_start_date=change_date-15;
current_start_date=change_date+1;
current_end_date=change_date+15;
call symputx('previous_end_date',previous_end_date);
call symputx('previous_start_date',previous_start_date);
call symputx('current_start_date',current_start_date);
call symputx('current_end_date',current_end_date);
put (_ALL_)(=);
format _numeric_ date9.;
run;
%put _USER_;
Do something like this
data _null_;
change_date= '01jul2018'd;
previous_end_date=change_date-1;
previous_start_date=change_date-15;
current_start_date=change_date+1;
current_end_date=change_date+15;
put (_ALL_)(=);
format _numeric_ date9.;
run;
If it is absolutely necessary to put them into macro variables, use call symput logic.
Thank you @PeterClemmensen for the answer. While I appreciate your answer, will those variables in Data be converted into Macro Variable?
If not, I give these variables in one program in Enterprise guide and use it in different programmes as well. Can these values be transferred to different programmes as well?
Thank you.
Use CALL SYMPUT logic to read the date values into macro variables like this
data _null_;
change_date= '01jul2018'd;
previous_end_date=change_date-1;
previous_start_date=change_date-15;
current_start_date=change_date+1;
current_end_date=change_date+15;
call symputx('previous_end_date',previous_end_date);
call symputx('previous_start_date',previous_start_date);
call symputx('current_start_date',current_start_date);
call symputx('current_end_date',current_end_date);
put (_ALL_)(=);
format _numeric_ date9.;
run;
%put _USER_;
@hvempati wrote:
Can you edit the format as '2018-07-02' (yy-mm--dd) in the answer. Thank you so much..!!
You can use the PUT() and QUOTE() functions with CALL SYMPUTX() .
call symputx('my_macro_var',quote(put(mysasdate,yymmdd10.),"'"));
Hi @Tom and @PeterClemmensen,
Do you think there would be a performance issue by using a method like this?
I was using a method where I was manually inputting all the dates. But now by using this method, I have seen the runtime for the same code was slow. (previously the code ran for 3 minutes, but now it runs for 10 minutes.) I haven't changed anything except this.
Any inputs on this?
Thank you.
@hvempati wrote:
Hi @Tom and @PeterClemmensen,
Do you think there would be a performance issue by using a method like this?
I was using a method where I was manually inputting all the dates. But now by using this method, I have seen the runtime for the same code was slow. (previously the code ran for 3 minutes, but now it runs for 10 minutes.) I haven't changed anything except this.
Any inputs on this?
Thank you.
There is no difference between running code like:
select * from have where date = '2017-12-01'
And the same code generated by using a macro variable.
%let mvar='2017-12-01';
...
select * from have where date = &mvar
If you are seeing a difference then either your data has changed or your query has changed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.