Date: Mon, 4 Mar 2002 10:56:02 -0800
Reply-To: prasad.s.ravi@HOUSEHOLD.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Prasad Ravi <prasad.s.ravi@HOUSEHOLD.COM>
Subject: Re: counting of specific values in a var row
Content-type: text/plain; charset=us-ascii
Annette:
Here is the code.
data one;
input VAR1 VAR2 VAR3 VAR4;
cards;
1 5 3 1
3 2 3 3
4 5 1 3
;
run;
data two;
set one;
new=0;
array all (*) var1-var4;
do i=1 to dim(all);
if all(i) in (1,2) then new=new+1;
end;
drop i;
run;
proc print;
run;
OUTPUT
Obs VAR1 VAR2 VAR3 VAR4 new
1 1 5 3 1 2
2 3 2 3 3 1
3 4 5 1 3 1
Prasad Ravi
Annette To: SAS-L@LISTSERV.UGA.EDU
<anne5432@UNI.DE> cc:
Sent by: "SAS(r) Subject: counting of specific values in a var row
Discussion"
<SAS-L@LISTSERV.U
GA.EDU>
03/04/2002 10:20
AM
Please respond to
Annette
dear SAS list,
I have a data set in the following structure:
VAR1 VAR2 VAR3 VAR4
1 5 3 1
3 2 3 3
4 5 1 3
All I want to do is to count the freqs of 1s and 2s in a row, and to add
their sum in a var NEW
VAR1 VAR2 VAR3 VAR4 NEW (sum of 1s and 2's in VAR1 to VAR4)
1 5 3 1 2
3 2 3 3 1
3 4 8 7 0
4 5 1 2 2
The real dataset contains dozends of vars.
Your help is greatly appreciated!
Annette