BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CydneyLB
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

Something like this ?

array f field:;

total_field=ifn(3 in f or (1 in f and 2 in f),3, field1);

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

Something like this ?

array f field:;

total_field=ifn(3 in f or (1 in f and 2 in f),3, field1);
CydneyLB
Obsidian | Level 7

This worked perfectly!

 

Thank you very much 🙂

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 736 views
  • 0 likes
  • 2 in conversation