Help using Base SAS procedures

Assigning value from SAS/AF Control to a Macro variable

Reply
Occasional Contributor
Posts: 18

Assigning value from SAS/AF Control to a Macro variable

Our department has several reports used by non-programmers.  The way they are currently set up is with a "macro" program and an "include" program.  A simplified version of the Macro program looks like this:

%LET State = TX ;

%LET Provider_Last_Name = Smith ;

/* some more %let statements */

%include "path/someprogram.sas" ;

Our users open this program in base SAS (9.2 or 9.3), change the appropriate inputs, and click "run."

Needless to say, this is not a perfect system.

I am trying to put together a SAS/AF form for one of these programs to see if it's feasible to use for a GUI to make things easier for our users.  We have other users who are programmers who use "power user" versions of the "macro" programs so I would like to have to make as few changes to the %included code as possible.

I've created a test form with a radio button list with four state abbreviations and a text entry box called Provider_Last_Name, and a Push Button called "Run".   Now I'm trying to figure out how to assign the input values to macro variables.  I'm sure it's something very simple I'm missing.  I can %PUT the values from the input controls into the log, but my %LET statements aren't working.

My SCL for the Run button (BTN_RUN) looks like this:

BTN_RUN:                                                                                                                               

/* this is the code that will execute when the RUN button (named BTN_RUN) executes */                                                  

submit continue;                                                                                                                       

                                                                                                                                      

%put NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS ;                                                            

%put NOTE- STATE:                  &STATE.selecteditem ;                                                                               

%put NOTE- PROVIDER_LAST_NAME:     &PROVIDER_LAST_NAME.text  ;                                                                         

                                                                                                                                      

/* now put those inputs into macro variables */                                                                                        

%LET STATE=                  &STATE.selecteditem ;                                                                                     

%LET PROVIDER_LAST_NAME=     &PROVIDER_LAST_NAME.text  ;                                                                               

                                                                                                                                      

%put NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS ;                                                            

%put NOTE- STATE:                  &STATE;                                                                                             

%put NOTE- PROVIDER_LAST_NAME:     &PROVIDER_LAST_NAME;                                                                                

                                                                                                                                      

/*eventually a %include will go here */                                                                                                

     endsubmit;                                                                                                                             

return;            

And my Log looks like this after I populate my controls and click Run:

92   %put NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS;

NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS

93   %put NOTE- STATE: TX;

      STATE: TX

94   %put NOTE- PROVIDER_LAST_NAME: TEST;

      PROVIDER_LAST_NAME: TEST

95   /* now put those inputs into macro variables */

96   %LET STATE= TX;

97   %LET PROVIDER_LAST_NAME= TEST;

98   %put NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS;

NOTE: PROGRAM STILL INSIDE FRAME SUBMIT BLOCK - THESE ARE THE INPUTS

99   %put NOTE- STATE: 4425;

      STATE: 4425

100  %put NOTE- PROVIDER_LAST_NAME: 4437;

      PROVIDER_LAST_NAME: 4437

101  /*eventually a %include will go here */

You can see that the values that are input are %PUT to the log, but the %LET statement assigning them to the macro variables I need to use are not working.

I'm guessing this is one of those simple things like when you have a macro variable resolve to another and you have to use 2 or 3 ampersands, I'm just stuck. I've tried a few things and could continue firing blindly, but I thought I'd ask for help.

Also, perhaps I need to put these values into a data set using the DATA step inside the form SCL then  populate macro variables from that - I really don't know...

Occasional Contributor
Posts: 18

Re: Assigning value from SAS/AF Control to a Macro variable

And, I just found the answer.  To assign the value at run-time not compile time, use Call Symput in the SCL code, (not inside a submit block).  Page 92 of the 9.2 SCL language reference.  D'oh!

Ask a Question
Discussion stats
  • 1 reply
  • 205 views
  • 0 likes
  • 1 in conversation