BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
changxuosu
Quartz | Level 8

Happy new year everyone!

Does anyone know this command in SAS:

 

%loopout:

%if x = 1 %then %goto loopout;

 

I saw this line of command in my SAS project that I'm currently working on. This project is built on previous work by other programmers that I have no contact of.

 

"loopout" isn't defined within the project I'm working on.

I'm wondering anyone know whether it is a SAS defined macro? I searched online and see no info about loopout

 

what does "%loopout:" and "%goto loopout" do?

 

THanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Look up in the SAS documentation the %goto statement.

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=mcrolref&docsetTarget=p0jfeh7...

 

%loopout is not a macro, it is a label, where you can direct the program to resume execution (which is what a GO TO does, it causes execution to not happen in a straight line down the program, but to jump to somewhere else)

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Look up in the SAS documentation the %goto statement.

https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=mcrolref&docsetTarget=p0jfeh7...

 

%loopout is not a macro, it is a label, where you can direct the program to resume execution (which is what a GO TO does, it causes execution to not happen in a straight line down the program, but to jump to somewhere else)

--
Paige Miller
changxuosu
Quartz | Level 8

thank you so much. it's very informative.

 

but what does the label do? I looked up the link you've provided which contains an example as below

 

%macro check(parm);
   %local status;
   %if &parm= %then %do;
       %put ERROR:  You must supply a parameter to macro CHECK.;
       %goto exit;
   %end;

   more macro statements that test for error conditions

   %if &status > 0 %then %do;
       %put ERROR:  File is empty.;
       %goto exit;
   %end;

   more macro statements that generate text

   %put Check completed successfully.;
%exit: %mend check;

 

 

my question is I tried two versions of this macro, one with the goto and exit combo; the other not.

I don't see any difference in the log and output SAS returns.

So what's the point of using this goto and exit combo?

Or is it because the above example macro is too simple to show the benefits of using goto?

Can I say it will become very useful if we're dealing with a big macro and needs to jump out of this macro some point

in the middle?

Thanks!

ballardw
Super User

@changxuosu wrote:

thank you so much. it's very informative.

 

but what does the label do? I looked up the link you've provided which contains an example as below

 

%macro check(parm);
   %local status;
   %if &parm= %then %do;
       %put ERROR:  You must supply a parameter to macro CHECK.;
       %goto exit;
   %end;

   more macro statements that test for error conditions

   %if &status > 0 %then %do;
       %put ERROR:  File is empty.;
       %goto exit;
   %end;

   more macro statements that generate text

   %put Check completed successfully.;
%exit: %mend check;

 

 

my question is I tried two versions of this macro, one with the goto and exit combo; the other not.

I don't see any difference in the log and output SAS returns.

So what's the point of using this goto and exit combo?

Or is it because the above example macro is too simple to show the benefits of using goto?

Can I say it will become very useful if we're dealing with a big macro and needs to jump out of this macro some point

in the middle?

Thanks!


The  LABEL is the target of a go to instruction. Depending on the actual executed program statements and conditions the LOG often does not show details of macro execution. You would have to run a program with the options mprint and mlogic to see what is happening internal to the macro. Without a complete macro, data sets and the parameters used to run the macro we cannot say anything in specific about your example. Sine the example you show tests for one form of blank parameter I would likely guess that you did not test with a blank value for your PARM parameter. Or perhaps your macro CHECK only examines values of the parameter and all of the  "log and output SAS returns" were generated by code outside of the macro CHECK. Your snippet of the macro does not show any way that the values of any of the tests would be passed outside of that macro so anything else is problematic as to "why".

changxuosu
Quartz | Level 8
thank you so much Ballardw!
PaigeMiller
Diamond | Level 26

The label indicates where the %GOTO will jump to. You execute the line with the %GOTO and the next line executed is the command after the label.

 

my question is I tried two versions of this macro, one with the goto and exit combo; the other not.

I don't see any difference in the log and output SAS returns.

So what's the point of using this goto and exit combo?

Or is it because the above example macro is too simple to show the benefits of using goto?

 

You haven't really given us an example. It's fragmentary code, with no data. And even in this case, if &status=0, the %goto never executes and you'd see no difference with or without the %goto.

--
Paige Miller
changxuosu
Quartz | Level 8
THANK YOU so much, Paige!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 682 views
  • 4 likes
  • 3 in conversation