Appreciate if someone of you guide me to combine the following if clauses to 'case when...' statement. I want to calculate the variable 'knkbty' and it should have values 1,3,4,5,6.
That's kinda messy code, and not workable (there are two unclosed DO blocks). Disregarding the hanging DO statements, I think that what you want may be something like this:
case
when knkatd ne knkatd_v then '6'
when agi ne agi_v then '1'
when knbjpn > knbjpn_v then '3'
when knkvpb in ('1','2','3') and knkvpb_v in ('4','5') then '3'
when knkvpb in ('4','5') and knkvpb_v in ('1','2','3') then '3'
when knbjpn < knbjpn_v then '4'
else '5'
end
Thank you. How to add the below condition in the following case when code to derive the value for KNKBTY=2 apart from 1,3,4,5 and 6?
if agi ne agi_v
then do;
knkbty = '1';
knkatv = '' ;
knkath = '' ;
agiteg = agi;
link schrijfv;
else
knkbty = '2';
knkatv = '' ;
knkath = '' ;
agiteg = agi_v;
Case when statement which I have right now is as below. I've to add the above condition in the case when to derive value for '2' as well.
case
when knkatd ne knkatd_v then '6'
when agi ne agi_v then '1'
when knbjpn > knbjpn_v then '3'
when knkvpb in ('1','2','3') and knkvpb_v in ('4','5') then '3'
when knkvpb in ('4','5') and knkvpb_v in ('1','2','3') then '3'
when knbjpn < knbjpn_v then '4'
else '5'
end
Your first if group tests on the relationship between knbjpn and knbjpn_v, and it exhausts all possible relations (you have one <, one > and one for =).
So your subsequent tests on AGI and KNKATD, if true, will supersede results based on knbjpn. Is that intentional?
Assuming it is, that's why @s_lassen's response reverses the order of the 3 main IF test groups, but maintains the order within the first group (if, else if, else).
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!
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.