Date: Wed, 5 May 2004 12:54:48 -0400
Reply-To: Bruce Johnson <bjohnson@SOLUCIENT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bruce Johnson <bjohnson@SOLUCIENT.COM>
Subject: Re: calculating the values of a variable.
Content-Type: text/plain; charset="windows-1255"
Here's tested code, and listing:
data string;
input @1 c1 $2.
@3 c2 $2.
@5 c3 $2.
@7 c4 $2.
@9 c5 $2.;
array nums (*) cn1-cn5;
array chars (*) c1-c5;
do i=1 to dim(nums);
nums{i}=input(put(chars{i},$5.),5.);***The length is dependent on the length of the
character variable;
end;
*---5---10---15; ***just a ruler for the data lines;
cards;
1 2 3 5
3 4 1 4 12
5 34 1 45
;
run;
proc means data=string n nmiss sum;
var cn1-cn5;
run;
The SAS System 11:48 Wednesday, May 5, 2004 1
The MEANS Procedure
N
Variable N Miss Sum
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
cn1 3 0 9.0000000
cn2 3 0 40.0000000
cn3 2 1 4.0000000
cn4 2 1 5.0000000
cn5 3 0 62.0000000
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Hope that helps!
________________________________
Bruce A. Johnson
bjohnson@solucient.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mayukh Dass
Sent: Wednesday, May 05, 2004 11:46 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: calculating the values of a variable.
Hi,
I have a dataset with string variables c1, c2, c3, ....... till c20. I am trying to calculate the total of the values of each variable. I also need to know how many missing values are present.
I tried:
data two;
set one end=eof;
if eof ne 1 then do;
cs1=input(c1,3.);
if c1=' ' then cs1=.;
tot1+cs1;
cs2=input(c2,3.);
if c2=' ' then cs2=.;
tot2+cs2;
cs3=input(c3,3.);
if c3=' ' then cs3=.;
tot1+cs3;
..........
end;
run;
but I am not getting proper answer.
Thanks,
Mayukh.
This message is a private communication. It may contain information that is confidential
and legally protected from disclosure. If you are not an intended recipient, please do
not read, copy or use this message or any attachments, and do not disclose them to others.
Please notify the sender of the delivery error by replying to this message, and then
delete it and any attachments from your system.
Thank you,
Solucient LLC
(rev eXclaimer 2x)
|