DATA Step, Macro, Functions and more

How to use %do %to on while running on remote servers

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

How to use %do %to on while running on remote servers

[ Edited ]

Hi all,

 

I recently noticed that, if I want to write a do loop or do a %let statement while on server, it does not work, and it seems that SAS simply ignores the line.

 

* sign on WRDS server;
rsubmit;

%do i = 1980 %to 2000; data a_&i; set ...; run; %end; endrsubmit;

log does not produce any line for that issue, it simply returns an error becasue a_i& is not resolved. The same thing happens if I want to use %let on the server. Is there a way that I can run such macro statements on the server? Or is there anything run with the code?

 

I am familiar with %syslput but somehow cannot figure how to use it with the %do loop. 

 

Thanks a lot,

 


Accepted Solutions
Solution
‎07-31-2017 11:34 AM
Respected Advisor
Posts: 4,173

Re: How to use %do %to on while running on remote servers

Posted in reply to Shayan2012

@Shayan2012

On top of what @Reeza wrote you need also to be quite carefule how you implement your macro code if combined with rsubmit in regards of timing. If you get it wrong then the macro compiler will resolve your macro stuff before the rsubmit gets executed resulting in the macro stuff being executed on your local machine even though you have it within the rsubmit block in your code.

http://support.sas.com/kb/23/986.html

https://support.sas.com/documentation/cdl/en/connref/69581/HTML/default/viewer.htm#n1wm9969gdtuijn19...

 

View solution in original post


All Replies
Super User
Posts: 19,772

Re: How to use %do %to on while running on remote servers

Posted in reply to Shayan2012

Macro code needs to generally be embedded in a macro. The code you posted will not work on a desktop either, you need working code in general first. Basically, your errors have nothing to do with being run on a server. 

 

%macro print_loop_useless();
%do i=1 %to 100;

proc print data=sashelp.cars(obs=&i);
run;

%end;
%mend;

%print_loop_useless();

 

 

Frequent Contributor
Posts: 75

Re: How to use %do %to on while running on remote servers

thanks Reeza, I actually had the macro statements, I forgot to put them here while copying and pasting. I do apologize for the inaccuracy.
Solution
‎07-31-2017 11:34 AM
Respected Advisor
Posts: 4,173

Re: How to use %do %to on while running on remote servers

Posted in reply to Shayan2012

@Shayan2012

On top of what @Reeza wrote you need also to be quite carefule how you implement your macro code if combined with rsubmit in regards of timing. If you get it wrong then the macro compiler will resolve your macro stuff before the rsubmit gets executed resulting in the macro stuff being executed on your local machine even though you have it within the rsubmit block in your code.

http://support.sas.com/kb/23/986.html

https://support.sas.com/documentation/cdl/en/connref/69581/HTML/default/viewer.htm#n1wm9969gdtuijn19...

 

Frequent Contributor
Posts: 75

Re: How to use %do %to on while running on remote servers

Thanks a lot, Patrick. I think my problem was actually the thing that you mentioned, and the documents helped solving the problem.
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 222 views
  • 2 likes
  • 3 in conversation