Date: Thu, 10 Mar 2005 11:21:36 -0500
Reply-To: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Subject: Re: PROC REPORT is not sorting properly
just try:
13 data temp2 ;
14 x=27.33 ;
15 y=9.44 ;
16 * put x best12. +3 y best12.;
17 length char1 char2 $12 ;
18 char1 = put(x,best12.) ;
19 char2 = put(y,best12.) ;
20 /*
21 if input(x,best12.) gt input(y,best12.)then put '27.33 > 9.44' ;
22 else if input(y,best12.) gt input(x,best12.) then put '9.44 > 27.33'
23 ; */
24
25 if compress(char1)<compress(char2) then put "27.33 < 9.44";
26 else put "9.44 < 27.33";
27 run ;
27.33 < 9.44
In deed SAS is comparing the formatted value as string. It does not "see"
the value behind that string! The comparision is byte by byte, so you see,
that "2" is less than "9" (just ignore the rest). You would also see that
"19999999" is less than "9" where 1999999 is NOT less than 9 !
On Thu, 10 Mar 2005 16:02:16 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Steve,
>
>if the var is numeric then your assumtions seem to be right, if it is a
>character then your assumtions are wrong because SAS will see 27.01 < 9.83 .
> Go back and look at your data going into proc report and see if the
>varibale you were tring to order with is character or numeric.
>
>
>
>Toby Dunn
>
>
>
>
>From: "James, Steve" <SPJ1@CDC.GOV>
>Reply-To: "James, Steve" <SPJ1@CDC.GOV>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: PROC REPORT is not sorting properly
>Date: Thu, 10 Mar 2005 10:46:43 -0500
>
>Thanks. That solves the problem but doesn't quite answer the question.
>How is it that the formatted value of 9.83 is greater than 27.33?
>
>The output has the behavior that if you drop the tens unit from the
>values that are over 9.99, then the sort order makes sense. Thus 9.83
>is larger than 27.33 => 7.33. However I can't understand why SAS would
>be doing that.
>What am I missing?
>
>According to the documentation, the default behavior for ORDER= is
>FORMATTED. The documentation also says that if an order variable does
>not have a format associated with it, then best12. is used. However I
>can't understand how, using best12. as a format, that 27.33 is somehow
>less than 9.83. Consider the following log:
>
>
>254 data temp2 ;
>255 x=27.33 ;
>256 y=9.44 ;
>257 * put x best12. +3 y best12.;
>258 length char1 char2 $12 ;
>259 char1 = put(x,best12.) ;
>260 char2 = put(y,best12.) ;
>261 if put(x,best12.) gt put(y,best12.)then put '27.33 > 9.44' ;
>262 else if put(y,best12.) gt put(x,best12.) then put '9.44 > 27.33'
>;
>263 run ;
>
>27.33 > 9.44
>NOTE: The data set WORK.TEMP2 has 1 observations and 4 variables.
>NOTE: DATA statement used (Total process time):
> real time 0.01 seconds
> cpu time 0.02 seconds
>
>
>Steve
>
>
>
>-----Original Message-----
>From: Ya Huang [mailto:ya.huang@AMYLIN.COM]
>Sent: Wednesday, March 09, 2005 6:18 PM
>To: SAS-L@LISTSERV.UGA.EDU; James, Steve
>Cc: Ya Huang
>Subject: Re: PROC REPORT is not sorting properly
>
>I got burnt by this before. If you read the mannual carefully,
>there are two 'order' in a define statement. First to tell that
>this var is an order var, second to tell what order you want. So change
>your define statement to this will work:
>
>
>define display_order / order order=internal descending noprint;
>
>
>Ya
>
>On Wed, 9 Mar 2005 17:52:44 -0500, James, Steve <SPJ1@CDC.GOV> wrote:
>
> >Dear SAS-L,
> >
> >
> >
> >I'm having a problem with PROC REPORT in that it's not sorting the
> >output properly. My PROC REPORT code has an ORDER variable as the
>first
> >variable in the COLUMNS statement. However, PROC REPORT is not sorting
> >the output in numerical order as I want it to. I can't figure out what
> >order it's using, but it's not numerical. If you run the following
> >program as is, you'll find that the first line of output has an
>fm_ratio
> >of 9.83. It's not sorted properly as there are a number of other
>values
> >that are above and below that value.
> >
> >
> >
> >However if I add a format to the DEFINE statement such as format=6.2,
>it
> >works. But if I add format=3.2 it does not. And it doesn't matter if
> >display_order is NOPRINT or not. I even tried creating an output
> >dataset out of the report output and both display_order and fm_ratio
>are
> >numeric variables with length 8, so it appears to be creating the
> >numeric variables correctly. This happens both in V8 and V9 on a
> >Windows platform.
> >
> >
> >
> >Can anyone tell me what's going on? This is strange!
> >
> >
> >
> >Steve
> >
> >
> >
> >Steve James
> >
> >Centers for Disease Control and Prevention
> >
> >sjames@cdc.gov
> >
> >
> >
> >
> >
> >
> >
> >data temp ;
> >
> >length symptom $25 vaccine $2 ;
> >
> >input fm_ratio vaccine symptom ;
> >
> >datalines ;
> >
> >27.333333333 TD NODULE_SKIN 5
> >
> >13 TD COUGH_INC 5
> >
> >12.592105263 TD VASODILAT 5
> >
> >12.266666667 TD EDEMA_PERIPH 5
> >
> >12 TD SKIN_STRIAE 5
> >
> >10.972972973 TD MASS_INJECT_SITE 5
> >
> >9.8333333333 TD LYMPHADENO 5
> >
> >9.7407407407 TD PRURITUS 5
> >
> >9.7096774194 TD HYSN_INJECT_SITE 5
> >
> >8.9333333333 TD INJECT_SITE_REACT 5
> >
> >;
> >
> >run ;
> >
> >
> >
> >proc report data=temp nowd missing headskip split='/' ;
> >
> >column fm_ratio=display_order vaccine symptom fm_ratio ;
> >
> >define display_order / order descending noprint
> >
> > /* format=6.2 - If I include this it works, without it, it does not */
> >
> > ;
> >
> >define vaccine / display 'Vaccine' width=10 ;
> >
> >define symptom / display 'Symptom' width=10 ;
> >
> >define fm_ratio / "F-M/Ratio" format=6.2 width=8 ;
> >
> >run ;
|