## Array variables to categorize by if all

Frequent Contributor
Posts: 78

# Array variables to categorize by if all

I want to categorize some variables only if all of the variables in the array meet all the criteria.  Any help on this would be greatly appreciated:

array ques{20} question1-question20;

do i=1 to 20;

if ques{i} ne . and ques{i}=4** then questcat=3;

end;

**only I want questcat=3 only if all of the nonmissing data in the array=4.

Thanks!

Super User
Posts: 23,663

## Array variables to categorize by if all

I'm not sure exactly what your rules are, seeing an example may help.

Guessing that if all questions values are 4 and none are missing then you could use the following logic:

max(of question1-question20)=min(of question1-question20) and nmiss(of question1-question20)=0 then ...

if your variables are character then you can try the cmiss function instead.

HTH,

Reeza

PROC Star
Posts: 8,163

## Array variables to categorize by if all

I'm not sure if I understand what you want to do.  It sound like:

data have;

input question1-question20;

cards;

1 2 3 4 . 4 . 3 2 1 1 2 3 4 . 4 . 3 2 1

;

data want;

set have;

array ques{*} question1-question20;

do i=1 to dim(ques);

ques=ifn(ques eq 4,3,.);

end;

run;

Valued Guide
Posts: 765

## Re: Array variables to categorize by if all

Hi ... you don't have to use an ARRAY.  Here's another idea (with only five questions, but it'll work with 20) ...

data test;

input q1-q5;

datalines;

4 4 4 4 4

. 2 3 1 4

4 . . . 4

. . . . .

1 2 3 4 5

. 4 4 4 .

;

run;

data test;

set test;

questcat = ifn(verify(catt(of q,'.4') or sum(of q eq . , 9 , 3);

run;

proc print data=test noobs;

run;

q1    q2    q3    q4    q5    questcat

4     4     4     4     4        3

.     2     3     1     4        9

4     .     .     .     4        3

.     .     .     .     .        9

1     2     3     4     5        9

.     4     4     4     .        3

"Searching for Variable Values with CAT Functions:  An Alternative to Arrays and Loops"

http://www.nesug.org/Proceedings/nesug09/ff/ff04.pdf

Frequent Contributor
Posts: 78

## Re: Array variables to categorize by if all

Great this is exactly what I need to do.

Thank you!

Discussion stats
• 4 replies
• 262 views
• 0 likes
• 4 in conversation