I want to update the ir.INSURANCE_CF dataset which should have the value for the variable INSURANCE_CONTRACT_GROUP_ID per the below calculation. With the below code I could only recreate the ir.INSURANCE_CF dataset whereas I was asked to only update the dataset.
Is there a way that we can tweak the code below to update the original dataset instead of recreating the same?
Could you please try the below code, we do not need to name the new variable as INSURANCE_CONTRACT_GROUP_ID_NEW, instead use the same existing name INSURANCE_CONTRACT_GROUP_ID
proc sql;
create table ir.INSURANCE_CF as
select
a.*,
b.INITIAL_RECOGNITION_DT,
compress(cats(a.INSURANCE_CONTRACT_GROUP_ID,put(a.ISSUE_DT,date9.),put(b.INITIAL_RECOGNITION_DT,date9.)),'.')
as INSURANCE_CONTRACT_GROUP_ID length=72
from IFRSLDIS.INSURANCE_CASHFLOW as a
left join IFRSLDIS.ADP_OUTPUT_NON_LIFE as b
on
a.REPORTING_DT = b.REPORTING_DT and
a.ENTITY_ID = b.UNIT and
cats(substr(put(ISSUE_DT,yymmn6.),1,4),"-",substr(put(ISSUE_DT,yymmn6.),5)) = b.ISSUE_MONTH
;
quit;
Since you change the structure, you can't update, only rewrite.
I don't see an opportunity for an update anyway, as you use
IFRSLDIS.INSURANCE_CASHFLOW IFRSLDIS.ADP_OUTPUT_NON_LIFE
as input to create a completely new dataset. You do not read
ir.INSURANCE_CF
anywhere in your code.
See this quick example for updating an existing column with data from another table:
data class;
set sashelp.class;
run;
data class1;
set sashelp.class (keep=Name);
x1 = _N_;
run;
proc sql;
update class a
set age = (select x1 from class1 b where b.name = a.name)
;
quit;
BTW, why do you still use
cats(substr(put(ISSUE_DT,yymmn6.),1,4),"-",substr(put(ISSUE_DT,yymmn6.),5))
when
put(ISSUE_DT,yymmd7.)
achieves the same (as I showed in your previous thread)?
I got it. Could you please tell me how will you optimize the code below to update the permanent table?
I'm trying to do optimize the above second step as follows, but I couldn't succeed as I'm not certain how to set the values in INSURANCE_CONTRACT_GROUP_ID
I've 16 columns in IFRSLDIS.INSURANCE_CASHFLOW and therefore I should have same columns in the final result with updated values for INSURANCE_CONTRACT_GROUP_ID
What does the SAS log tell you when you execute the SQL as posted?
1. A SQL update can only change values in existing cells. It can NOT add columns or rows. So: Any DROP statement is already wrong.
2. You update CELLS and for this reason the sub-select must return exactly one value. The sub-select must also be valid SQL code which yours isn't.
select * from temp compress(cats(INSURANCE_CONTRACT_GROUP_ID,put(ISSUE_DT,date9.),put(INITIAL_RECOGNITION_DT,date9.)),.
Please try and check that again - like all cats() stuff needs to go into the select clause and you also need to add a where condition to only select the row which matches the record in the table you want to update. May be try first to fully understand the sample code @Kurt_Bremser posted and also read up how a SQL Update works in documentation.
I won't waste a second of my time trying to read this ugly piece of spaghetti text.
Please supply CODE.
See my many posts (and those of the other superusers and PROC STARS) for how to write code in a readable manner.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.