%macro gen_base(Portofo,dev) data &Portofo._VAL (KEEP= MOB DQ_6); set monthly.score_&Portofo.(keep=account_no CURR_DELQMONTH_ON_BOOK bad); .... run; gen_base(old_gwic_others_&P_YYMMDD.,Gwic_old_others);
Hi All I am having the above code and I am not sure what is the value of &Portofo._VAL on the second line , the data line.
should it be old_gwic_others_&P_YYMMDD.? or old_gwic_others_&P_YYMMDD._VAL...
and &dev would be "Gwic_old_others"
%gen_base(old_gwic_others_&P_YYMMDD.,Gwic_old_others);
data &Portofo._VAL (KEEP= MOB DQ_6); >>> old_gwic_others_&P_YYMMDD._VAL set monthly.score_&Portofo.(keep=account_no CURR_DELQMONTH_ON_BOOK bad); >>> monthly.score_old_gwic_others_&P_YYMMDD.
Here is a very simple way to test what it would be.
%macro parmtest(portofo); %put resolved value of '&portofo._val' is: &portofo._val; %mend; %parmtest(old_gwic_others_&p_yymmdd.))
This is a very basic skill. If you don't know how to do something like this you should not be writing or trying to diagnose macros.
Or run the code with OPTIONS MPRINT;
@HeatherNewton wrote:
%macro gen_base(Portofo,dev) data &Portofo._VAL (KEEP= MOB DQ_6); set monthly.score_&Portofo.(keep=account_no CURR_DELQMONTH_ON_BOOK bad); .... run; gen_base(old_gwic_others_&P_YYMMDD.,Gwic_old_others);Hi All I am having the above code and I am not sure what is the value of &Portofo._VAL on the second line , the data line.
should it be old_gwic_others_&P_YYMMDD.? or old_gwic_others_&P_YYMMDD._VAL...
and &dev would be "Gwic_old_others"
As posted, this will result in an ERROR because of the failed attempt to call the macro (missing %).
Once this is corrected, first the macro variable P_YYMMDD is resolved, and the completed string of old_gwic_others_<content of macro variable P_YYMMDD> is fed as parameter portofo to the macro.
In the macro, you'll get
data old_gwic_others_<content of macro variable P_YYMMDD>_VAL (KEEP= MOB DQ_6);
and
set monthly.score_old_gwic_others_<content of macro variable P_YYMMDD>(keep=account_no CURR_DELQMONTH_ON_BOOK bad);
It's all "just" simple text replacement.
There are two ways to create arguments to a macro ... with an equal sign, and without an equal sign
Without an equal sign (this is what you did)
%macro gen_base(Portofo,dev);
data &Portofo._VAL (KEEP= MOB DQ_6);
set monthly.score_&Portofo.(keep=account_no CURR_DELQMONTH_ON_BOOK bad);
....
run;
%mend;
In this case the order of the variables in the call to the macro is critical
%gen_base(old_gwic_others_&P_YYMMDD.,Gwic_old_others)
means that &PORTOFO = old_gwic_others_&P_YYMMDD. and &DEV = Gwic_old_others
Or, if you reverse the order
%gen_base(Gwic_old_others,old_gwic_others_&P_YYMMDD.)
this means that &PORTOFO = Gwic_old_others and &DEV = old_gwic_others_&P_YYMMDD.
With equal signs, the order they are called is irrelevant
%macro gen_base(Portofo=,dev=);
data &Portofo._VAL (KEEP= MOB DQ_6);
set monthly.score_&Portofo.(keep=account_no CURR_DELQMONTH_ON_BOOK bad);
....
run;
%mend;
Then both of these produce the exact same results:
%gen_base(portofo = old_gwic_others_&P_YYMMDD., dev = Gwic_old_others)
%gen_base(dev = Gwic_old_others, portofo = old_gwic_others_&P_YYMMDD.)
I strongly recommend the style where you use the equal signs, as this removes any ambiguity about which macro variable has which value. It probably doesn't matter if your macro has one or two arguments, but if you write a macro with lots of arguments, without the equal signs you will have to keep track of which argument is the 6th, and which argument is the 7th, and so on; this is easy to get wrong. If you use the equal signs, then it is always clear which macro variable is getting which value.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: