Search code examples
saspromptsas-macroenterprise-guide

Macro Automization via Prompts in SAS EG


here is my table

 data:
 ax bx cx dx ex fx
 1   2  3  4  5 5
 2   3  5  1  0 5
 3   7  8  9  1 4

here is my basic code

%macro example(c= , b= ,a= );
 data temp;
 set  data;
diff = &c-(&b+&a);
run;
%mend example;
% example(c=cx ,b=bx ,a=ax)

I want to automize diff = c-(b+a) by setting a prompt-like feature in SAS EG but I do not know how to do it? My aim is to be able change my features(for example instead cx, I want to put f or instead ax,e and so on) in "diff" equation because my actual data consists of thousands of columns. If you help me, I appreciate.


Solution

  • To automate this, you'd probably want to make three prompts. One for each variable (c,b,a). (Of course, call them something descriptive, not c,b,a!) Select "use throughout project" and "requires non blank value". Maybe add some more useful text to describe what they are.

    Then, you need to have a way of populating them. You can either populate them from a static list (enter the possible values in), just as open text boxes where you'll type them in yourself each time, or you can populate them from a data source. The mechanics of populating from a data source depends on your local setup - are you using "local EG" or is it EG connected to a metadata server, for example - but overall it should be fairly straightforward.

    Either on "User selects values from a static list", select "Get values", then "Browse" for the SAS data file; or "User selects values from a dynamic list", do the same. The latter will always check the data source for updates, while the former just populates the list at prompt creation time.

    Finally, in your program, your macro call would then look like:

    %example(c=&c ,b=&b ,a=&a)
    

    where &c &b &a are the prompt names (the 'short' name if you gave it a longer text name also).