BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Suzy_Cat
Pyrite | Level 9

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

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Reeza
Super User
Add another %IF/%THEN branch?
Suzy_Cat
Pyrite | Level 9

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);

 

 

Tom
Super User Tom
Super User

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;
Suzy_Cat
Pyrite | Level 9

Hi Tom! Exactly! I had the same idea, and it works!!

 

Thank you for being there and providing ideas !

 

 

Amir
PROC Star

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1316 views
  • 4 likes
  • 4 in conversation