Hi SAS Forun,
I have hard coded the same date in 2 different places in a lengthy code (see yellow highlights).
data k.Arr_Histry_filtrd_haphaz_rmvd;
set tt;
by bank_number account_number current_date;
if first.account_number
then _f1 = (current_date ne '28FEB2010'd and Arrears_Band
ne 'Current') ;
retain _f1;
if _f1 ne 1 then output;
drop _:;
run;
After the above code, I have several other code pieces below.
………………………………….
………………………………….
………………………………….
………………………………….
………………………………….
Then I get another code like below.
data t1 k.write_off_History_GE_FEB2010; /*you should use a.write_off_History_GE_FEB2010 file throughout and not a.write_off_History*/
set k.write_off_History;
if post_date <'28FEB2010'd then output t1;
else output k.write_off_History_GE_FEB2010;
run;
Question:
I want to turn the above hard coding into a macro.
Could any macro expert please let me know if the following macro is logically OK?
Can I use the same macro name, i.e. %macro first_1(mth), in two different places in the same code?
%let t_1=28FEB2010;
%macro first_1(mth);
data k.Arr_Histry_filtrd_haphaz_rmvd;
set tt;
by bank_number account_number current_date;
if first.account_number
then _f1 = (current_date ne '&mth'd and Arrears_Band
ne 'Current') ;
retain _f1;
if _f1 ne 1 then output;
drop _:;
run;
%mend first_1;
%first_1(mth=&t_1);
After the above code, I have several other code pieces below.
………………………………….
………………………………….
………………………………….
………………………………….
………………………………….
Then I get another code like below.
%macro first_1(mth);
data t1 k.write_off_History_GE_FEB2010; /*you should use a.write_off_History_GE_FEB2010 file throughout and not a.write_off_History*/
set k.write_off_History;
if post_date <'&mth'd then output t1;
else output k.write_off_History_GE_FEB2010;
run;
%mend first_1;
%first_1(mth=&t_1);
Thank you for your help
Mirisage
You can always test it...
But a few comments, once you create a macro variable you can use it as many times as you.
And you can only resolve macro variables within double quotes, not single quotes. Well you can within single quotes but you need a different function for that.
The
'&mth'd
should be
"&mth"d
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.