Hi All
I want to calculate amounts for a large number of codes eg:
if code in ('BBB','PPP') then amount = 1;
but I want it to exclude the codes PPPBB and PPPCC as that code will be calculated separately eg:
if code in ('PPPBB','PPPCC') then amount = 2;
Sorry can't get my head around this.
Thank you
Hi,
Looks like you have everything you need. Try:
data want;
input code $;
if code in ('BBB','PPP') then
amount = 1;
else
if code in ('PPPBB','PPPCC') then
amount = 2;
datalines;
PPPBB
PPP
PPPCC
BBB
;
Regards,
Amir.
Message was edited by: Amir Malik - formatting
Hi,
Looks like you have everything you need. Try:
data want;
input code $;
if code in ('BBB','PPP') then
amount = 1;
else
if code in ('PPPBB','PPPCC') then
amount = 2;
datalines;
PPPBB
PPP
PPPCC
BBB
;
Regards,
Amir.
Message was edited by: Amir Malik - formatting
Hi Amir
The 1st in statement will select all codes that have PPP in them including PPPBB which I do not want.
Hi,
Looking at the data set produced, I see the following:
Obs code amount
1 PPPBB 2
2 PPP 1
3 PPPCC 2
4 BBB 1
Did you want something different? If yes, then please give sample input data and the output data you want to see.
Regards,
Amir.
Thanks Amir 🙂
Hi,
No problem. As you might have realised, the in operator, as used in the code, will check if the variable is equal to any one of the values in the parentheses, not contained in one of the values.
Hope that's clear.
Regards,
Amir.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.