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

Hope someone can help me.

 

I would like to call a macro from within another macro but only every time 'category' changes, and then pass the initiate macro the value of a variable sorted_profile_table.

 

I have spent hours on this and all the help online isn't helping, thank you for your assistance!  

 

Here is the code (pseudocode in some cases): 

 

%macro load_control_tables;

 

 proc sort data=profile_table out=sorted_profile_table;
  by category;
 run;

 

 data _null_;
  set sorted_profile_table ;
  by category;

 

  if first.category then
  do;  
      call another macro (called %initiate) using the VALUE of a VARIABLE from sorted_profile_table (as a macro variable)
  end;
 run;

%mend;

 

 The macro @initiate is within another program and has been run.

 

Thanks folks!
Mark

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

You need Call execute

 

Please refer to the technical paper by the genius none other than Ian whitlock

http://www2.sas.com/proceedings/sugi22/CODERS/PAPER70.PDF

 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

You need Call execute

 

Please refer to the technical paper by the genius none other than Ian whitlock

http://www2.sas.com/proceedings/sugi22/CODERS/PAPER70.PDF

 

markc
Obsidian | Level 7
Thank you very much novinosrin, worked! Good on you 🙂
markc
Obsidian | Level 7

Hello there,

 

Subsequent to this, what if the parameters to a macro call are longer than 262 characters, it seems CALL EXECUTE fails in this case?

 

Kind regards,

Mark

RW9
Diamond | Level 26 RW9
Diamond | Level 26

If your having parameters that long then consider re-working your process.  There is never a need to use macros, just change the way of thinking about things.  One of the main things we see pop up here is people passing in lists of items.  Take this example, you need to filter off a list of items, you could put those items in a macro parameter like:

%macro filter (list=);
  proc sql;
    select * from have where myvar in (&list.);
  quit;
%mend filter;

Now if your list grows this type of thing can get unwieldy and hard to program with.  Use the power of datasets makes this far simpler, just with a simple change of thinking:

%macro filter (listds=);
  proc sql;
    select * from have where myvar in (select var from &listds.);
  quit;
%mend filter;

In this instance we have a dataset with our values, and pass that into the macro, the dataset can be any size and be used just like any other dataset.   

 

With regards to the "longer than 262 characters, it seems CALL EXECUTE fails in this case?" - what do you mean fails?  What happens, what is in the log etc.  Do you mean you get a warning about length, if so there is: options noquotelenmax; which will turn off that warning, make sure to turn it back on afterwards.

sas-innovate-2024.png

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.

 

Register now!

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
  • 4 replies
  • 745 views
  • 1 like
  • 3 in conversation