Hi there
can anyone provide suggestions to improve below codes?
Currently below codes works:
%Macro AddInfoTo_DS (DS_in, Var, DS_out);
%_eg_conditional_dropds(&DS_out);
%let result = ;
/* if &Var exist then do nothing, else run the relevant programme to add &Var */
%VarExist(&DS_in, &Var);
%if "&result"="0" %then %do;
%Add_ID_ByName (&DS_in, &DS_out);
%end;
%Mend;
%AddInfoTo_DS (&InputData, ID, Step2_Dump);
Ideally, I would like to include macro "%Add_ID_ByName (&DS_in, &DS_out);" as part of the parameters to run macro "%AddInfoTo_DS (&InputData, ID, Step2_Dump);"
i.e. when a particular information is missing, then run the relevant programme to add that piece of info to the dataset.
Is there any chance to get that done?
Thanks
Sue
Why are you trying to make this so complicated?
You could pass in the NAME of the macro you want to call.
%macro addinfoto_ds
(ds_in
,var
,ds_out
,submacro_name
);
%_eg_conditional_dropds(&ds_out);
%varexist(&ds_in, &var);
%if "&result"="0" %then %do;
%&submacro_name (&ds_in, &ds_out);
%end;
%mend addinfoto_ds;
Hey Reeza, Thanks for your suggestions,
I am testing below codes and hope it will eventually works:
%Macro AddInfoTo_DS (DS_in, Var, DS_out);
%_eg_conditional_dropds(&DS_out);
%let result = ;
%VarExist(&DS_in, &Var);
%if "&result"="0" %then %do;
%put ResultBefore="&result";
%Add_&Var (&DS_in, &DS_out);
%put ResultAfter="&result";
%end;
%Mend;
%AddInfoTo_DS (&InputData, ID, Step2_Dump);
%AddInfoTo_DS (Step2_Dump, Day, Step2_Dump);
Why are you trying to make this so complicated?
You could pass in the NAME of the macro you want to call.
%macro addinfoto_ds
(ds_in
,var
,ds_out
,submacro_name
);
%_eg_conditional_dropds(&ds_out);
%varexist(&ds_in, &var);
%if "&result"="0" %then %do;
%&submacro_name (&ds_in, &ds_out);
%end;
%mend addinfoto_ds;
Hi Tom! Exactly! I had the same idea, and it works!!
Thank you for being there and providing ideas !
@Suzy_Cat , well done on supplying your code and thinking along the same lines as the given answer.
If any of the replies has given you the answer you wanted then please mark it as the solution (not this post) as it can help others to easily find a solution to a similar problem and it is an additional acknowledgement of the time and effort taken by the person who has posted the answer.
Kind regards,
Amir.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.