DATA Step, Macro, Functions and more

How to define a macro variable for SAS connect?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

How to define a macro variable for SAS connect?

 

Hi,

I am writing a program which includes connecting to a web service (WRDS databases) to download some data. As I have noticed, if I define the macro variables before connecting to the WRDS, it will not recognize the varibale. This is what I have right now:


%let bgnyr = 2002;
%let endyr = 2004;

%signonWRDS;

proc sql;
create table crspfund as select * from want
where &bgnyr <= year(caldt) <= &endyr;
quit;

 

So this does not work, because the macro variables are not recognized. I know that If I define the macro varibales after connection, it works. like this:

 

%signonWRDS;

 

%let bgnyr = 2002;
%let endyr = 2004;

 

proc sql;
create table crspfund as select * from want
where &bgnyr <= year(caldt) <= &endyr;
quit;

 

But then, If I disconnect and continue on my local machine, I need to redefine the macro variables. I know that it is not a big deal, but I was curious to know if there is a way to define the macros in a general way that it will apply to both situations at once?

 

Thanks a lot

 


Accepted Solutions
Solution
‎10-03-2016 04:08 PM
Super User
Posts: 3,254

Re: How to define a macro variable for SAS connect?

[ Edited ]
Posted in reply to Shayan2012

 My suspicion is that the %signonWRDS macro hides a remote submit to a remote SAS server (RSUBMIT). Defining your macro variable before the remote submit defines them for your local SAS session only. When you define them after the remote submit then it defines them on the remote server session where the SQL query runs.

 

You can use %SYSLPUT to define your local macro variables in the remote session once you have signed on:

 

http://support.sas.com/documentation/cdl/en/connref/67933/HTML/default/viewer.htm#n1bc4zi0lp02ivn1ox...

 

View solution in original post


All Replies
Solution
‎10-03-2016 04:08 PM
Super User
Posts: 3,254

Re: How to define a macro variable for SAS connect?

[ Edited ]
Posted in reply to Shayan2012

 My suspicion is that the %signonWRDS macro hides a remote submit to a remote SAS server (RSUBMIT). Defining your macro variable before the remote submit defines them for your local SAS session only. When you define them after the remote submit then it defines them on the remote server session where the SQL query runs.

 

You can use %SYSLPUT to define your local macro variables in the remote session once you have signed on:

 

http://support.sas.com/documentation/cdl/en/connref/67933/HTML/default/viewer.htm#n1bc4zi0lp02ivn1ox...

 

Frequent Contributor
Posts: 75

Re: How to define a macro variable for SAS connect?

Thanks a lot. %SYSLPUT seems like the exact thing I was looking for!

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 316 views
  • 1 like
  • 2 in conversation