Date: Mon, 5 Jun 2000 20:18:47 +0100
Reply-To: peter.crawford@DB.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <peter.crawford@DB.COM>
Subject: Re: Do loop problem
Content-type: text/plain; charset=us-ascii
Betreff: RE: Do loop problem
Nachrichtentext:
Hello again, to the -List
and
Thank you to Ian for the generous tolerance of my temposary spelling error.
The algorithm might improve to sum absolute differences,
or square of differences....
The optimal form of output would depend on the objectives
of the algorithm.
Optimal solutions and logical flaws are separate from my objectives.
I was trying to show how remarkably simple it is to
implement the pseudo code in base SAS, unchanged (almost).
But without criticising the posters pseudo code.
My implementation of the pseudo code causes one error no-one
seems to have referred to.
P(I) = P;
will fail (probably always) because an array cannot have the
same name as a variable and vice versa, at least, in base SAS.
There is a simple variation (using rename) which will complete
a working demo of how easy that pseudo code could be trialled
To load an array, and run Paul's pseudo code
data _null_ ;
/* define and load the array */
array P(100) _temposary_;
do i = 1 to 100;
set <your data set>( rename=p=PC ) ;
p(i) = PC ;
end;
/* Paul's code follows */
TOT=0;
DO I=1 TO 100;
DO J=1 TO 100;
TOT= TOT+ abs( (P{I}-P{J}) );
END;
END;
/* now output the total, for example */
put tot= ;
stop;
run;
This thread seems to have generated considerable response !
Regards
Peter
Datum: 05.06.2000 17:32
An: Peter Crawford/Zentrale/DeuBaExt
Betreff: RE: Do loop problem
Nachrichtentext:
Peter,
%put tot=0 ;
Ian Whitlock <whitloi1@westat.com>
-----Original Message-----
From: Peter Crawford [mailto:peter.crawford@DB.COM]
Sent: Monday, June 05, 2000 12:27 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Do loop problem
To load an array, and run Paul's pseudo code
data _null_ ;
/* define and load the array */
array P(100) _temposary_;
do i = 1 to 100;
set <your data set> ;
p(i) = p ;
end;
/* Paul's code follows */
TOT=0;
DO I=1 TO 100;
DO J=1 TO 100;
TOT=TOT+(P{I}-P{J});
END;
END;
/* now output the total, for example */
put tot= ;
stop;
run;
It might get a little more complex if there are more or less than 100 obs.
Regards
Peter Crawford
Datum: 05.06.2000 17:00
An: SAS-L@listserv.uga.edu
Antwort an:
Betreff: Do loop problem
Nachrichtentext:
This is a multi-part message in MIME format.
--------------A48C53391317DD06EF919CCF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I would appreciate any help with what should be a trivial programing
problem. Essentially, I have created a SAS data set containing one
variable, P, with 100 observations in it. I would now like to execute
the following pseudo code (which finds the sum of all possible
differences between the observtions in P) within a subsequent DATA
statement.
TOT=0;
DO I=1 TO 100;
DO J=1 TO 100;
TOT=TOT+(P{I}-P{J});
END;
END;
Thanks,
Paul Maxim
--------------A48C53391317DD06EF919CCF
Content-Type: text/x-vcard; charset=us-ascii;
name="maxim.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Paul Maxim
Content-Disposition: attachment;
filename="maxim.vcf"
begin:vcard
n:Maxim;Paul
tel;fax:519-661-3200
tel;home:519-473-0413
tel;work:519-661-2111 Ext. 85121
x-mozilla-html:FALSE
org:University of Western Ontario;Sociology
adr:;;;London;Ontario;N6A 5C2;Canada
version:2.1
email;internet:maxim@uwo.ca
end:vcard
--------------A48C53391317DD06EF919CCF--