DATA Step, Macro, Functions and more

%goto error

Reply
New Contributor
Posts: 4

%goto error

Hello

I'm editing a SAS program with %macro/%mend funkction. For this macro I will make some loop´s. If Loop 1 is finished go to Loop 2 aso.

In the report I have:

%macro projekt_schleife();

*Code 1;

/*
################################################################################################################     */

/* Uebersicht   */

proc sql;

create table work.uebersicht as

select     out.stand,

           out.&ebene,

           out.position,

     sum(out.aktuell_kumuliert_gj) format=commax16.2 as aktuell_kumuliert_gj,

     sum(out.aktuell_kumuliert_vj) format=commax16.2 as aktuell_kumuliert_vj,

     sum(out.aktuell_kumuliert_vvj) format=commax16.2 as aktuell_kumuliert_vvj,

 

           sum(out.vormonat_gj)format=commax16.2 as vormonat_gj,

     sum(out.vormonat_vj)format=commax16.2 as vormonat_vj

from sasco2.output_bs_vbeitrag
as out
where out.&ebene IN (&vb)

group by 1, 2, 3;

quit;

This ist the Code for the Loops. I Need the same request for every single Loop.

%let top_x = 25;

%let grenze1 = 100000;

%let grenze2 = 30000;

%let grenze3 = 5000;

 

/******************Loop 1******************/

  %Goto | %Go to label1;

  %label1: %let bereich = P0;                    

            %let bereich_druck = 'P0'; 

             %let vb ='P';

             %let ebene =vb0;

%projekt_schleife();

;

 

/******************Loop 2******************/

%Goto | %Go to label2;

%label2:     %let bereich = P1;                        

                            %let bereich_druck= 'P1';             

                            %let vb ='1'; 

                           %let ebene = vb1;

%projekt_schleife();

  ;


The error message is indicating that  "The %GOTO statement is not valid in open code." and "Statement is not valid or it is used out of proper order."

But what does this mean and how can I edit above to work? 

Thanks for any and all assistance.


Respected Advisor
Posts: 3,887

Re: %goto error

It looks to me as if you've copied code snippets from some other program and now try to paste these together and "make it work". It would be better you first try to write the actual logic in simple SAS code and then "macrotize" it.

So first thing which is currently missing: A %mend; statement which finishes the macro definition. You also shouldn't call macro %projekt_schleife() within it's own macro definition unless you like never ending loops.


The open code error means that you're trying to use a macro statement outside of a macro definition.


New Contributor
Posts: 4

Re: %goto error

Oh you´re right I forgot to write  %projekt_schleife() at the end in this post. But it doesn´t work with this correct Code.

Thats means, I have to put the %macro code together with the %goto-Code? I will get the same Error. Smiley Sad There is something wrong with the %goto macro

New Contributor
Posts: 4

Re: %goto error

For a single Loop the code is running but I can´t compare 2 Loops....

Super User
Super User
Posts: 7,401

Re: %goto error

I agree with Patrick, there are various issues in the code and it doesn't make sense.  Also I don't see that this code is actually doing anything.  Start by describing what you are trying to do, post a datastep with some test data, and required output.

Respected Advisor
Posts: 3,887

Re: %goto error

I still don't understand what you are actually trying to achieve. Hopefully below code sample can give you some guidance.

%macro projekt_schleife(bereich,bereich_druck,vb,ebene);

  data _null_;

    put "bereich      =&bereich";

    put "bereich_druck='&bereich_druck'";

    put "vb           ='&vb'";

    put "ebene        =&ebene";

    stop;

  run;

%mend;

%macro project(top_x);

  %let grenze1 = 100000;

  %let grenze2 = 30000;

  %let grenze3 = 5000;

  %if %eval(&top_x<25) %then

    %do;

      %projekt_schleife(P0,P0,P,vb0)

    %end;

  %else

    %do;

      %projekt_schleife(P1,P1,1,vb1)

    %end;

%mend;

%project(30);

%project(10);

New Contributor
Posts: 4

Re: %goto error

Thanks all for your answer. I din´t put all issues from the code in this post because it´s too much data. Is it possible to send the hole code per E-Mail. I don´t want to present it online.

Super User
Posts: 5,081

Re: %goto error

For SAS to consider this open code, it is likely that the mistake is earlier.  There is likely some sort of unfinished comment statement before this code appears, which also comments out the %macro project_schleife statement.

Super User
Super User
Posts: 6,499

Re: %goto error

The syntax for a %GOTO statement is just %goto label; .  Why do you have pipe characters in the middle of your %GOTO statements?

Are you planning to call the macro recursively?  If so make sure that it exits without calling itself again.  I do not see any conditional statements in your macro that would prevent it from getting into an infinitely nested recursive loop.

If not then you will need another macro to be able to use %GOTO statement. You cannot use it in open code.

Ask a Question
Discussion stats
  • 8 replies
  • 726 views
  • 0 likes
  • 5 in conversation