Date: Thu, 24 Mar 2005 15:40:24 -0800
Reply-To: Jim Simmons <emailjimsimmons@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jim Simmons <emailjimsimmons@YAHOO.COM>
Subject: Re: sort.
In-Reply-To: <7eb98a8b050324144263b8b35c@mail.gmail.com>
Content-Type: text/plain; charset=us-ascii
Nishant,
I rarely use verify, but I think you have it right. If not,
someone on this listserv will let you know! Another alternative
would be to eliminate the undesireable obs. when you create the
dataset with a subsetting IF statement:
DATA DS1;
SET or INPUT statement that gets the data into this data set.
IF VI IN('S','B','1','2','3','4','5','6','7','8','9','0');
. . .
IF VI='S' THEN VI='A';
RUN;
PROC SORT EBCDIC;
BY P VI;
RUN;
DATA DS2;
SET DS1;
IF VI='A' THEN VI='S';
RUN;
The obs that you do not want should be eliminated prior to the
sort regardless of the technique you use. If the data is
already in a SAS data set, you should substitute the WHERE
expression for the subsetting IF. If you are using an INPUT
statement to get external data into a SAS data set, do not
substitute the WHERE expression. In general it is better to
keep unwanted obs out of your data set than to include them and
then delete them.
Jim Simmons
--- Nishant Dholakia <nishant.dholakia@GMAIL.COM> wrote:
> Thanks Jim,
> Now to add to the complexity of the issue I have values
> besides A and B like
> GU and U3 (this data is really messy).
> I came up with verify function
> I only want s b and numeric values (numeric values in vi are
> in char form too).
>
> so this is what i did
> temp = verify (vi, 'sb1234567890');
> if temp>0 then delete;
>
> This should hopefully give me observations only where numeric
> values
> or s and b are present.
> is there a better way to do it.
> thanks
>
>
> On Wed, 23 Mar 2005 17:10:23 -0800, Jim Simmons
> <emailjimsimmons@yahoo.com> wrote:
> > Nishant,
> >
> > No, this will not work with the S required to appear before
> the
> > B. However, the following should work with the data
> starting
> > out in a data set named DS1:
> >
> > DATA DS1;
> > SET or INPUT statement that gets the data into this data
> set.
> >
> > . . .
> >
> > IF VI=S THEN VI=A;
> > RUN;
> >
> > PROC SORT EBCDIC;
> > BY P VI;
> > RUN;
> >
> > DATA DS2;
> > SET DS1;
> > IF VI=A THEN VI=S;
> > RUN;
> >
> > Now, data set DS2 should be sorted in the desired manner.
> >
> > Jim Simmons
> >
> >
> > --- Nishant Dholakia <nishant.dholakia@GMAIL.COM> wrote:
> > > Hi,
> > > I will definitely try that out. However I just want to be
> sure
> > > because
> > > vi has a value of S and B and S should be placed before B.
> Is
> > > that the
> > > sorting order of EBCDIC.
> > > I have not had a chance to try my own solution of
> implementing
> > > a
> > > special missing value and creating a sorting variable.
> > > what do you think about it.
> > >
> > > Thanks
> > >
> > >
> > > On Tue, 22 Mar 2005 10:42:39 -0800, Jim Simmons
> > > <emailjimsimmons@yahoo.com> wrote:
> > > > Nishant,
> > > >
> > > > Dennis is correct that the EBCDIC collating sequence
> will
> > > correctly sort your data. You can invoke this sequence in
> > > non-EBCDIC environments with the following:
> > > >
> > > > PROC SORT EBCDIC;
> > > > BY P VI;
> > > > RUN;
> > > >
> > > > That seems to me to be the easiest way assuming you
> already
> > > have the missing numeric value for DO in obs 5 represented
> by
> > > a "."(SAS missing numeric value).
> > > >
> > > > Jim Simmons
> > > >
> > > > Dennis Diskin <diskin@SNET.NET> wrote:
> > > > Nishant,
> > > >
> > > > Unless you are running on an EBCDIC system (IBM
> > > > mainframe), in which case you can just sort:
> > > >
> > > > My suggestion:
> > > >
> > > > sort normally on p and vi and then:
> > > >
> > > > data ordered;
> > > > set sorted(where=(vi eq 'b'))
> > > > sorted(where=(bi ne 'b'));
> > > > by p;
> > > > run;
> > > >
> > > > HTH,
> > > > Dennis Diskin
> > > >
> > > > --- Nishant Dholakia
> > > > wrote:
> > > > > Hi,
> > > > > I have to create data set in which data is supposed
> > > > > to be like this
> > > > >
> > > > > p vi do
> > > > > 1 b 20
> > > > > 1 3 40
> > > > > 1 4 40
> > > > > 2 b 20
> > > > > 2 3
> > > > >
> > > > > basically the sorting has to be done by p and vi.
> > > > > However the issue I am
> > > > > facing is that vi is character values. using input i
> > > > > can convert the values
> > > > > to numeric and sort however there is one value (b)
> > > > > that can not be
> > > > > manipulated this way. the value b should always be
> > > > > the first for any p
> > > > > value.
> > > > > b is already present so I can not use the logic if
> > > > > first.p then vi =b;
> > > > > Is there some way to do this.
> > > > >
> > > > > thanks
> > > > >
> > > >
> > >
> > >
> > > --
> > > Nishant H. Dholakia
> > > 607 262 0860
> > >
> > > "its your attitude not your aptitude that determines your
> > > altitude"
> > >
> >
>
>
> --
> Nishant H. Dholakia
> 607 262 0860
>
> "its your attitude not your aptitude that determines your
> altitude"
>
|