Date: Fri, 12 Jan 2007 13:27:26 +0100
Reply-To: Spousta Jan <JSpousta@CSAS.CZ>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Spousta Jan <JSpousta@CSAS.CZ>
Subject: Re: How can I round an expression to 2 decimal points?
Content-Type: text/plain; charset="iso-8859-2"
Just for the record, this can be even more powerful (and dangerous because it rewrites directly the variables in the list).
define rndmore (!pos=!char(',') / !pos = !cmd ).
* Rounds variables in the second argument to the precision given in the first argument.
* Both arguments separated by comma.
* The second argument can contain list of variables, and even use TO .
compute #@prec = 10**!1.
do repe @var = !2.
- compute @var = rnd(@var * #@prec) / #@prec .
end repe.
!enddefine.
GET FILE='C:\Program Files\SPSS\Cars.sav'.
rndmore -2, engine to weight year.
exe.
Greetings
Jan
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Marta García-Granero
Sent: Friday, January 12, 2007 9:43 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: How can I round an expression to 2 decimal points?
Hi Jan (and Boika)
Just for fun...
SJ> I agree with you that the optional second argument would be easier.
DEFINE !ROUND(!POS=!CHAREND('=')/!POS=!CHAREND(',')/!POS=!TOKENS(1)).
COMPUTE !1=RND(!2*(10**!3))/(10**!3).
LIST VAR=!2 !1 /CASES=FROM 1 TO 5.
!ENDDEFINE.
!ROUND rounded2=varname,2.
--
Best regards,
Marta