I am trying to modify a value in a field in one data set based on criteria for this and another data set. Here is my current code, which doesn't work. My code should change the hazard code from MO to WM in table B where the claim number is the same between the two tables and there are values in the first table for both loss causes WM and WI.
proc sql;
UPDATE TABLE_B AS B
HAZARD_CODE_INDICATOR = 'WM'
FROM TABLE_A AS A
where
A.CLM_NBR = B.CLM_NBR AND
A.LOSS_CAUSE = 'MO' AND
(B.HAZARD_CODE_INDICATOR = 'WM' AND
B.VALUES <> 0) AND
(B.HAZARD_CODE_INDICATOR = 'WI' AND
B.VALUES <> 0));
quit;
Here are the error messages I receive:
23 proc sql;
24 UPDATE TABLE_B AS B
25 HAZARD_CODE_INDICATOR = 'WM'
_____________________
79
26 FROM FROM TABLE_A AS A
____ __
22 76
202
ERROR 79-322: Expecting a SET.
ERROR 22-322: Syntax error, expecting one of the following: ;, !!, *, **, +, ',', -, /, WHERE, ||.
ERROR 76-322: Syntax error, statement will be ignored.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
26 ! FROM FROM TABLE_A AS A
__
22
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
Thank you for any help you can provide,
Christine
The following should work.
data table_a;
CLM_NBR=1;
LOSS_CAUSE = 'MO';
HAZARD_CODE_INDICATOR='WM';
output;
stop;
run;
data table_b;
CLM_NBR=1;
HAZARD_CODE_INDICATOR = 'WI';
VALUES=1;
output;
CLM_NBR=1;
HAZARD_CODE_INDICATOR = 'XX';
VALUES=1;
output;
stop;
run;
proc sql;
UPDATE TABLE_B AS B
set HAZARD_CODE_INDICATOR = 'WM'
where
B.HAZARD_CODE_INDICATOR = 'WI' AND
B.VALUES <> 0 AND
exists
(
select *
from table_a as a
where
A.CLM_NBR = B.CLM_NBR AND
A.LOSS_CAUSE = 'MO' AND
A.HAZARD_CODE_INDICATOR = 'WM'
)
;
quit;
I don't think SAS SQL supports updates with a join using SQL.
Try creating a new table using SQL rather than updating the table.
The following should work.
data table_a;
CLM_NBR=1;
LOSS_CAUSE = 'MO';
HAZARD_CODE_INDICATOR='WM';
output;
stop;
run;
data table_b;
CLM_NBR=1;
HAZARD_CODE_INDICATOR = 'WI';
VALUES=1;
output;
CLM_NBR=1;
HAZARD_CODE_INDICATOR = 'XX';
VALUES=1;
output;
stop;
run;
proc sql;
UPDATE TABLE_B AS B
set HAZARD_CODE_INDICATOR = 'WM'
where
B.HAZARD_CODE_INDICATOR = 'WI' AND
B.VALUES <> 0 AND
exists
(
select *
from table_a as a
where
A.CLM_NBR = B.CLM_NBR AND
A.LOSS_CAUSE = 'MO' AND
A.HAZARD_CODE_INDICATOR = 'WM'
)
;
quit;
Thank you very much, Patrick! You saved my bacon! I've been struggling with this for a while and was nearing a deadline.
Seabird
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: