| Date: | Tue, 11 Aug 2009 10:41:09 -0400 |
| Reply-To: | Sigurd Hermansen <HERMANS1@WESTAT.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Sigurd Hermansen <HERMANS1@WESTAT.COM> |
| Subject: | Re: PROC SQL weirdness |
|
| In-Reply-To: | <1b2f75c0-d6c8-418d-bd50-e929e4da79d3@g31g2000yqc.googlegroups.com> |
| Content-Type: | text/plain; charset="us-ascii" |
SAS doesn't have an integer data type in PROC SQL or the Data step. If we "Whitlock" the problem you've posted, we see that the program produces expected results when X has integer values. I've replaced GROUP BY with ORDER BY. If you are looking to group values by year and setting conditions on groups, instead of ordering by year, see the alternative version of the program.
data tab0;
do year = 2008 to 2010;
do i=1 to 5;
X=round(ranuni(23473)*11,1.);
output;
end;
end;
run;
proc sql;
create table tab1 as
select X, year
from tab0
where X between 1 and 10
and X ne 9
order by year;
quit;
proc sql;
create table tab2 as
select MAX(X) as X, year
from tab0
group by year
having X between 1 and 10
and X ne 9
;
quit;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Pinux
Sent: Tuesday, August 11, 2009 7:11 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: PROC SQL weirdness
On 11 Ago, 12:42, Chris Jones <chris...@gmail.com> wrote:
> On 11 Aug, 09:46, Pinux <xflot...@gmail.com> wrote:
>
>
>
> > I have a numeric variable X which ranges from 1 to 10 and I would like
> > to select all the values except for 9.
> > If I run the following PROC SQL:
>
> > proc sql;
> > create table tab1 as
> > select X, year
> > from tab0
> > where X between 1 and 10
> > and X ne 9
> > group by year;
> > quit;
>
> > I get X=1,2,3,4,5,6,7,8 but not X=10.
> > I have enconuntered this weird behaviour only on SAS/Unix while the
> > same program run on z/OS and WinXP selects the right values. Any ideas
> > on what can be the source of this weirdness?
> > Thanks in advance.
>
> Numeric precision? I.e. 10 doesn't exactly equal 10!
>
> Try
>
> where round(X,1) between 1 and 10
>
> or
>
> where put(round,z2.) between '01' and '10'
Thanks for the response.
The variable X has only integer values so I guess I can exlude the
issue has something to do with numeric precision, can't I?
|