BookmarkSubscribeRSS Feed
RameshReddy
Calcite | Level 5

hi,

I am trying to execute below mentioned code , syserror is resolving always ZERO ,if any error occurs still its resolving 0 , any one can tell what"s wrong on this code

%macro test;

proc print data=sashelp.clss;

run;

proc sql noprint;

select Count(*) into :CONT from sashelp.class;

quit;

options symbolgen ;

%put &SYSERR;

%if (&cont = 0 and &syserr=0) or (&cont = 0 and &syserr > 0) or

(&cont > 0 and &syserr > 0)

%then %do ;

%let V_STATUS=0;

%end;

%else;

%IF &cont > 0 and &syserr=0  %THEN %do ;

%let V_STATUS=1;

%end;

%mend;

%test;

Regards,

Ramesh

5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12

Check the manual for SYSERR, "SYSERR automatic macro variable is reset at eachstep boundary."  The SQL procedure ran.

RameshReddy
Calcite | Level 5

not clear with your answer ...

Doc_Duke
Rhodochrosite | Level 12

&syserr is set to 3000 by the failing PROC PRINT, but it is reset to 0 by the successful PROC SQL, so it is always 0 when it gets to your %IF statements.

Put the OPTIONS SYMBOLGEN; at the top to see what is going on.

art297
Opal | Level 21

What are you trying to find out?  Doc already explained about syserr and it being set to 3000 because of the sashelp.clss file doesn't exist, but what are you expecting?

Your v_status macro variable won't resolve after the macro as it is a local rather than global macro variable.

TriciaA
Calcite | Level 5

Run this code and it will be more clear what is happening:  The bold line is especially important.

%macro test;

title "This is my test";

proc print data=sashelp.clas;

run;

%put SYSERR is this value: &syserr.;

proc sql noprint;

select Count(*) into :CONT from sashelp.class;

quit;

%put SYSERR is this value: &syserr.;

%put CONT is this value: &cont.;

%if (&cont = 0 and &syserr=0)

          or (&cont = 0 and &syserr > 0)

          or (&cont > 0 and &syserr > 0)

%then %do ;

%let V_STATUS=0;

%end;

%else;

%IF &cont > 0 and &syserr=0  %THEN %do ;

%let V_STATUS=1;

%end;

%put V_STATUS is this value:  &V_STATUS.;

%mend;

%test;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2668 views
  • 0 likes
  • 4 in conversation