Date: Wed, 20 Aug 2008 15:23:48 -0400
Reply-To: Bucher Scott <SBucher@SCHOOLS.NYC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bucher Scott <SBucher@SCHOOLS.NYC.GOV>
Subject: Re: Improve the code
In-Reply-To: <cb416ac10808201148k4d52f9f5qed4489a35cdeb70b@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"
I believe the 'truncation' is occurring due to the following if - else
if statement. The 'else if' is missing a 'then' so it is probably acting
as a subsetting if.
28 if round(sum( t_FW, t_FJ)) ge 4 then S = 15;
29 else if S = round(9/2*sum(t_FW, tot_FJ),.1);
You cannot convert directly convert a variable from character to a
numeric number, which it sound like you are trying to do (?).
-Scott
From: syk ghb [mailto:sghb02@gmail.com]
Sent: Wednesday, August 20, 2008 2:48 PM
To: Bucher Scott
Cc: SAS-L@listserv.uga.edu
Subject: Re: Improve the code
Hi Scott,
Right, it helps great than creating two datasets... but I am getting
strange Notes: Forexample, the first NOTE reads: Numeric values have
been converted to character values at the places given by:
(Line):(Column).
17:9 18:9
even though I am trying to change character to Numeric ??? I thought
input is from character to Numeric.
Second, Strange my d2 is trucated 4656 observations to 1565 ????? any
reason
Third, I also getrid of the notes for the missing values which is the
last NOTE
Background: All the q's and p's variables are text. I am converting to
Numeric to make algebric operation using 'input' function.
Thank
syk
6 data d2;
7 set d;
8 array q[11] q1 - q9 q83 q84;
9 array p[11] p1 - p9 p83 p84;
10 array F[11] F1 - F9 F83 F84;
11
12 do i = 1 to 11;
13
14 if q[i] = "*" then q[i]=' ';
15 if p[i] = "*" then p[i]=' ';
16
17 q[i] = INPUT(q[i], 1.);
18 p[i] = INPUT(p[i], 1.);
19
20 if q[i] in (0,1,2,3,4,5,6,7) then F[i]=0;
21 else if q[i] in (8,9) then F[i]=q[i]*p[i];
22
23 end;
24
25 t_FW = sum (of F1 - F9);
26 t_FJ = sum (F83, F84);
27
28 if round(sum( t_FW, t_FJ)) ge 4 then S = 15;
29 else if S = round(9/2*sum(t_FW, tot_FJ),.1);
30 drop i;
31 run;
NOTE: Numeric values have been converted to character values at the
places given by:
(Line):(Column).
17:9 18:9
NOTE: Character values have been converted to numeric values at the
places given by:
(Line):(Column).
20:12 21:17 21:50 21:59
NOTE: Missing values were generated as a result of performing an
operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
8 at 21:58 5 at 25:14 16 at 26:14 5 at 28:8 5 at 28:14
5 at 29:22
5 at 29:32 5 at 29:33
NOTE: There were 4656 observations read from the data set WORK.D.
NOTE: The data set WORK.d2 has 1565 observations and 37 variables.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.09 seconds
On Wed, Aug 20, 2008 at 1:24 PM, Bucher Scott <SBucher@schools.nyc.gov>
wrote:
Not sure if this is much in the way of an improvement:
data d2;
set d;
array q{*} q: ;
array p{*} p: ;
array f{*} f: ;
do _n_ = 1 to dim(q);
if q[_n_] = "*" then q[_n_]=' ';
if p[_n_] = "*" then p[_n_]=' ';
q [_n_] = input(q[_n_], 1.);
p [_n_] = input(p[_n_], 1.);
if q[_n_] in (0,1,2,3,4,5,6,7) then f[_n_]=0;
else if q[_n_] in (8,9) then f[_n_]=q[_n_]*p[_n_];
end;
t_fw = sum (of f1 - f9);
t_fj = sum (f23, f24);
if round(sum( t_fw, t_fj)) ge 8 then s = 15;
else if s = round(9/2*sum(t_fw, t_fj),.1);
run;
-Scott
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of syk
Sent: Wednesday, August 20, 2008 1:21 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Improve the code
Hi All
I just want to make this code more efficient and terse. But, I am not
sure
how?? Especially,I want to collaps the code for d2 and d3. I will also
repeat similar code for other
variables q10-q22 q24-q50 in the same dataset.
data d
id q1 q2 q3 q4 q5 q6 q7 q8 q9 q23 q24 p1 p2 p3 p4 p5 p6 p7 p8 p9 p23
p24
1 1 7 8 6 5 8 7 8 5 7 6 2 2 2 2 2 2 2 2 2 2 2
2 2 3 8 * 5 8 5 7 8 2 4 4 4 4 4 4 4 4 4 4
3 3 8 4 7 2 4 8 8 4 5 3 3 3 3 3 3 3 3 3 3
4 4 8 0 2 2 3 1 4 6 2 3 1 1 1 1 1 1 1 1 1 1 1
..
data d2;
set d;
array q[11] q1 - q9 q23 q24;
array p[11] p1 - p9 p23 p24;
do i = 1 to 11;
if q[i] = "*" then q[i]=' ';
if p[i] = "*" then p[i]=' ';
end;
drop i;
run;
data d3;
set d2;
array q[11] q1 - q9 q23 q24;
array p[11] p1 - p9 p23 p24;
array F[11] F1 - F9 F23 F24;
do i = 1 to 11;
q [i] = INPUT(q[i], 1.);
p [i] = INPUT(p[i], 1.);
if q[i] in (0,1,2,3,4,5,6,7) then F[i]=0;
else if q[i] in (8,9) then F[i]=q[i]*p[i];
end;
t_FW = sum (of F1 - F9);
t_FJ = sum (F23, F24);
if round(sum( t_FW, t_FJ)) ge 8 then S = 15;
else if S = round(9/2*sum(t_FW, t_FJ),.1);
drop i;
run;