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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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