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 (April 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 13 Apr 2010 14:42:51 -0700
Reply-To:     "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Schwarz, Barry A" <barry.a.schwarz@BOEING.COM>
Subject:      Re: Is this a FORMAT issue??
In-Reply-To:  <20100413172653.PVR39887@punts3.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

You need to print out the values of y using a format that shows as many decimal places as possible. Chances are the values you quoted below are only approximations to two decimal places.

Furthermore, most decimal fractions cannot be represented exactly. So when your if attempts to compare to &test as in your example, the actual comparand is probably something along the lines of 31.240000013. Unless your value of y happens to be the same approximation of 31.24, it will not compare equal.

Two possible solutions are fuzzy compares or character compares such as if compress(put(y,5.2),' ') = "&test";

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of My Name Sent: Tuesday, April 13, 2010 2:27 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Is this a FORMAT issue??

I want to subset a data set based on the value of "y" below. Consider data set "old":

x y 11 0.00 12 15.62 13 31.24 14 43.74 15 56.24 16 68.74 17 78.12 18 84.38 19 90.62 20 93.74 21 96.88

This data set was created within a macro and now I want to create a "new" data set containing only a single observation such as:

%let test=31.24;

data new;set old; if y=&test; proc print; run;

The weird thing is... SAS is not recognizing certain values of the "test" macro variable. Even though the value of "31.24" is in data set "old", it is not evaluating it correctly.

Incorrectly evaluates: 15.62 31.24

Correctly evaluates: 0 43.74 56.24 68.74 78.12 84.38 90.62 93.74 96.88

The column description for the "y" variable is:

Type: Num Length: 8 Format: BEST12. Informat: 12.

Any ideas?

Thanks,

Lewis


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