BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

Hello everyone,

It seems in the SAS code below ,%goto statement doesn't work properly in a data step.

please advise.

Thanks!.

Mike

%macro testgoto(aaa);
data one;
x=symget('aaa');
put x=;
if x='ok' then do;

put ''x=ok;
%goto exit;
end;
else
do;

put 'x ^=ok';
end;
run;
%put Before exit;
%exit:
%put after exit;
%mend testgoto;


%testgoto(aaa=ok);

3 REPLIES 3
Tom
Super User Tom
Super User

%GOTO doesn't have anything to do with a data step.  It is part of SAS macro language. SAS macro language is just used to generate text strings that SAS can then try to interpret as a program.

Your macro has no macro logic in it.  So the generated code will always be:


data one;
x=symget('aaa');
put x=;
if x='ok' then do;

put ''x=ok;

That is not even a complete data step.  So if you call this macro you will need too at least add an END; statement to close the DO loop that the code generated by the macro started.

PaigeMiller
Diamond | Level 26

This is not an appropriate use of Macro statements. You can accomplish everything you need in a data step, without ever using a macro. See the documentation for the LINK statement for examples on how to branch to specific code.

--
Paige Miller
Sidi
Calcite | Level 5

Hello,

You can use goto in a data step but without the percentage at the begining.

Just goto instead of %goto.

Hope this help.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1441 views
  • 0 likes
  • 4 in conversation