LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2007)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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?
Comments: To: Marta García-Granero <biostatistics@terra.es>
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


Back to: Top of message | Previous page | Main SPSSX-L page