BookmarkSubscribeRSS Feed
statadm
Fluorite | Level 6

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!

4 REPLIES 4
Reeza
Super User

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

art297
Opal | Level 21

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;

MikeZdeb
Rhodochrosite | Level 12

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

More info at ...

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

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


statadm
Fluorite | Level 6

Great this is exactly what I need to do.

Thank you!

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
  • 4 replies
  • 1787 views
  • 0 likes
  • 4 in conversation