Skip to content
Back to formatted view

Raw Message

Message-ID: <CANVKczMgxQXey8Gt2ANjNXO6Q4MP4=60VgwGQTH9bMCsZzh5OQ@mail.gmail.com>
Date: 2012-10-11T07:50:10Z
From: Barry Rowlingson
Subject: How to replicate SAS by group processing in R
In-Reply-To: <d323f35d779f4e29ac2911d1fa9544b6@EX-0-HT0.lancs.local>

On Wed, Oct 10, 2012 at 7:09 PM, ramoss <ramine.mossadegh at finra.org> wrote:

> In SAS I use the following code:
>
> proc sort data=upper;
> by tdate stock_symbol expire  strike;
> run;
> data upper1;
>   set upper;
>   by tdate stock_symbol expire  strike;
>   if first.expire then output;
>   rename strike=astrike;
> run;
>
> on the following data set:
>
> tdate   stock_symbol    expiration      strike
> 9/11/2012       C                          9/16/2012    11
> 9/11/2012       C                          9/16/2012    12
> 9/11/2012       C                          9/16/2012    13
> 9/12/2012       C                          9/16/2012    14
> 9/12/2012       C                          9/16/2012    15
> 9/12/2012       C                          9/16/2012    16
> 9/12/2012       C                           9/16/2012   17
>
> to get the following results:
> tdate   stock_symbol    expiration      strike
> 9/11/2012       C                          9/16/2012    11
> 9/12/2012       C                          9/16/2012    14
>
> How would I replicate this kind of logic in R?

 First, replicate it in some kind of universally understood language -
like English. Nearly every alien in every sci-fi film I've seen speaks
English, so that's a safe assumption :)

 What does it do? Take the first record within groups defined by
tdate? Why does your code say 'expire' but the data have 'expiration'?

Barry