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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 397 views
  • 2 likes
  • 3 in conversation