mkharraz
mkharraz

Reputation: 61

SAS: Case When then execute query

I want to execute a query only when a condition is satisfied. The code I want to execute is:

proc sql NOPRINT OUTOBS=1;
%CASE WHEN (&_count_ > 0) THEN
DELETE FROM TABLE T
WHERE T.Period = xxxxxx
END;
quit;

Upvotes: 1

Views: 255

Answers (3)

Petr
Petr

Reputation: 376

proc sql;
DELETE FROM T
WHERE &_count_ > 0 and Period = xxxxxx
;quit;

Upvotes: 1

mkharraz
mkharraz

Reputation: 61

i found the solution:

%macro delete_rows();
PROC SQL;
DELETE FROM Table T
WHERE Period=xxxxxx;
QUIT;
%mend;

%macro check_if();
%IF (&nbr_rows > 0) %THEN 
    %delete_rows();
%mend;

Upvotes: 1

DineshDB
DineshDB

Reputation: 6193

Use IF instead of CASE:

proc sql NOPRINT OUTOBS=1;
%IF(&_count_ > 0) %THEN %DO
DELETE FROM TABLE T
WHERE T.Period = xxxxxx
%END;
quit;

Upvotes: 1

Related Questions