Hi,
I currently have data that looks like this:
ID Field_1 Field_2 Field_3 Field_4 Field_5
1 3 1 . . .
2 1 2 1 . .
3 1 1 . . .
4 2 3 2 . .
5 2 . . . .
6 1 1 1 3 3
ect
I need to create a new variable (Total_Field) based on the values in Fields 1- 5 as follows:
If any Field is 3 then Total_Field = 3
if an id has both a Field = 1 & a Field = 2 then Total_Field = 3
if an id has only Field's= 1 then Total_Field = 1
if an id has only Field's = 2 then Total_Field = 2.
So for the above data Total_Field would be:
ID Total_Field
1 3
2 3
3 1
4 3
5 2
6 3
I know i could do this with if then statements but it would be really long winded so I'm hoping there is a quicker way?
Thanks
Cydney
Hello,
Something like this ?
array f field:;
total_field=ifn(3 in f or (1 in f and 2 in f),3, field1);
Hello,
Something like this ?
array f field:;
total_field=ifn(3 in f or (1 in f and 2 in f),3, field1);
This worked perfectly!
Thank you very much 🙂
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.