BookmarkSubscribeRSS Feed
yakamoz
Calcite | Level 5

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.


8 REPLIES 8
Patrick
Opal | Level 21

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.


yakamoz
Calcite | Level 5

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

yakamoz
Calcite | Level 5

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Patrick
Opal | Level 21

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);

yakamoz
Calcite | Level 5

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.

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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.

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!

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
  • 8 replies
  • 3589 views
  • 0 likes
  • 5 in conversation