BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dennis_oz
Quartz | Level 8

Hi all,

what can i put in the %abend  part of the program to safely stop code execution . I do not want any further steps to be executed

*---------------------------------------------------------------------------------------------------------------*

 

%macro Check(file_upload_date.)
proc sql;
create table t1 as
select max(Response_File_Load_Date) as max_File_Load_Date format=date9.
into :max_File_Load_Date
from My_lib.Table1
/* where dt < today() and flg = 0*/
;quit;

%put &max_File_Load_Date.;

%if &max_File_Load_Date. >= &file_upload_date. %then %abend;

%mend;
%check(&file_upload_date.);

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

you can try like below

 

%macro Check(file_upload_date.)
proc sql;
create table t1 as
select max(Response_File_Load_Date) as max_File_Load_Date format=date9.
into :max_File_Load_Date
from My_lib.Table1
/* where dt < today() and flg = 0*/
;quit;

%put &max_File_Load_Date.;

%if &max_File_Load_Date. >= &file_upload_date. %then %do;
%abort;
%end;
%mend;
%check(&file_upload_date.);
Thanks,
Jag

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

you can try like below

 

%macro Check(file_upload_date.)
proc sql;
create table t1 as
select max(Response_File_Load_Date) as max_File_Load_Date format=date9.
into :max_File_Load_Date
from My_lib.Table1
/* where dt < today() and flg = 0*/
;quit;

%put &max_File_Load_Date.;

%if &max_File_Load_Date. >= &file_upload_date. %then %do;
%abort;
%end;
%mend;
%check(&file_upload_date.);
Thanks,
Jag
Kurt_Bremser
Super User

First of all, you need to make sure that your code works at all. Maxim 2: Read the Log:

 ERROR: Symbolic variable name FILE_UPLOAD_DATE. must contain only letters, digits, and underscores.
 ERROR: Invalid macro parameter name FILE_UPLOAD_DATE..  It should be a valid SAS identifier no longer than 32 characters.
 ERROR: A dummy macro will be compiled.
 72         
 73         %macro Check(file_upload_date.)
 74         proc sql;
 75         create table t1 as
 76         select max(Response_File_Load_Date) as max_File_Load_Date format=date9.
 77         into :max_File_Load_Date
 78         from My_lib.Table1
 79         /* where dt < today() and flg = 0*/
 80         ;quit;
 81         %put &max_File_Load_Date.;
 82         %if &max_File_Load_Date. >= &file_upload_date. %then %abend;
 ERROR: Macro keyword ABEND is not yet implemented.
 83         %mend;

First fix the issue with the invalid macro parameter name.

Then use a %put statement instead of the (invalid) %abend statement. Testing that will reveal that your comparison will not work as intended because you formatted the macro variable max_File_Load_Date with DATE9.; 01MAY2020 is "smaller" than 30APR2020 in a text comparison. Maxim 28: Macro Variables Need No Formats. The raw numeric values will always work correctly.

Follow Maxim 1 (Read the Documentation) to find out how to abort a SAS session with a macro statement:

Macro Statements 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 851 views
  • 2 likes
  • 3 in conversation