| Date: | Tue, 7 Jun 2005 20:33:01 +0530 |
| Reply-To: | Praveen <ipkrishna@gmail.com> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Praveen <ipkrishna@GMAIL.COM> |
| Subject: | Re: How to add a new column by counting the order of observation? |
| In-Reply-To: | <200506071405.j57E5JG2031899@listserv.cc.uga.edu> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
One of the other way might be
data two;
retain index;
set one;
index+1;
run;
Ptaveen
On 6/7/05, Venky Chakravarthy <swovcc@hotmail.com> wrote:
> I see that several stalwarts have already weighed in. Since none of the SQL
> folks have had their say, I wanted to point out the undocumented, but
> reasonably well known MONOTONIC() function which is normally associated
> with SQL but is also available to the DATA STEP. Tested in 8.2 as well as
> 9.1.3.
>
> data toindex ;
> input t Demand ;
> cards ;
> 1 23
> 2 34
> 3 45
> 4 41
> 5 36
> 6 11
> 7 101
> 4 25
> 3 11
> 2 80
> 1 19
> run ;
>
> proc sql ;
> create table withindex as
> select monotonic() as index , *
> from toindex ;
> quit ;
>
> data withindex2 ;
> index = monotonic() ;
> set toindex ;
> run ;
>
>
> On Mon, 6 Jun 2005 14:55:29 -0400, Fred <ieaggie2002@GMAIL.COM> wrote:
>
> >Hi, a newbie's question again.
> >Given the current data:
> >t Demand
> >1 23
> >2 34
> >3 45
> >4 41
> >5 36
> >6 11
> >7 101
> >4 25
> >3 11
> >2 80
> >1 19
> >
> >I want to put a new column index such that the new data set looks like:
> >index t Demand
> >1 1 23
> >2 2 34
> >3 3 45
> >4 4 41
> >5 5 36
> >6 6 11
> >7 7 101
> >8 4 25
> >9 3 11
> >10 2 80
> >11 1 19
> >
> >I know it would be pretty easy and forget how to do this.
> >Sorry to waste your time on this.
> >
> >Fred
>
--
P. Krishna,
New Delhi,
India.
|