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!
Look up in the SAS documentation the %goto statement.
%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)
Look up in the SAS documentation the %goto statement.
%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)
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!
@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".
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: