DATA Step, Macro, Functions and more

Passing macro variable to another macro

Posts: 71

Passing macro variable to another macro

[ Edited ]

Hi All,


SO currently I have been working on a SAS script where I have to get UserID and password through the below code:-


%let userid=;
%let pass = ; 

%MACRO login;
%WINDOW info
#1 @2 'QSP LOGIN:' attr=highlight
#5 @5 'Please enter userid:'
#5 @26 userid 20 attr=underline
#7 @5 'Please enter password:'
#7 @28 pass 20 attr=underline display=no;
%DISPLAY info;

%MEND login;


and the pass the obtained value of userid and password to another  macro which looks like this:-




but this is giving error :

Apparent symbolic reference not resolved.


Please help!

Super User
Posts: 10,211

Re: Passing macro variable to another macro

[ Edited ]

Use %global so that the macro variables are placed in the global table. Otherwise they are only defined in the table local to the macro.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,599

Re: Passing macro variable to another macro

Wow, someone actually uses %window.  To be honest I wouldn't advise to do this, usernames & passwords are very delicate and belong to the user.  You would need to be extremely careful on each level to keep this secure and hidden, not easy if you passing it around in macro variables.  Consult with your IT group before attempting this, it is likely there are more secure and validated processes to extract data from a database (which is what you appear to be doing) then handling it yourself, such as encrypted login authentication files, secure portals etc.  If your program messes up and passwords appear in the log...

Posts: 71

Re: Passing macro variable to another macro

[ Edited ]

All I want is to get the ID & password of the user (which they'll input) and propogate it further to a macro and then to a Java API. Please let me know if there is some other facility to do that. As of now I am trying to do this using %windows. I am a noob in SAS Macro porgramming.

Super User
Super User
Posts: 9,599

Re: Passing macro variable to another macro

As I said, your best option will be to discuss this with your IT group and see what they can provide.  Its likely they can link the user directly in without further code.  Dealing with it yourself is quite dangerous.  Remember SAS creates a log file, if you take passwords and use them without anything further they can appear in the log - it just worries me that you might undermine the security of your whole system if you do not do these things properly.

Valued Guide
Posts: 533

Re: Passing macro variable to another macro

On a side note you should keep an eye on the quoting of the password value. If passwords are complex (as they should be) they could easily contain characters that will throw off the execution of your code. Something like %NRBQUOTE() would make it more robust. So test your program with passwords that contain ampersands, punctuation, whitespace, single and double quotes as they are famous for causing havoc in SAS programs if not properly escaped. Just for fun try a password like the quote killer:




Good luck,

- Jan.

Super User
Posts: 6,753

Re: Passing macro variable to another macro

This seems like a long-shot ... but so does everything else.  I'm only suggesting it because your results indicate it's a possible cause.


You have two %LET statements at the beginning of your program.  By any chance, did the statements appear in a different order?  More specifically, did your program try to execute %qspDataTransfer before executing those %LET statements?


If that's not the case, we'll need to see the contents of %qspDataTransfer because there could be some other macro variable causing the problem (even a simple mis-spelling of a macro variable name).

Ask a Question
Discussion stats
  • 6 replies
  • 1 like
  • 5 in conversation