Date: Sat, 15 Oct 2005 23:46:11 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: Summing the variable (shares) between two dates
Content-Type: text/plain; charset=ISO-8859-1
Naser,
As Toby mentioned, some sample data and desired output would definitely
help. However, that said, do the following last steps do what you are
trying to accomplish:
data c;
retain sum;
merge a(in=in1) b(in=in2);
by cnum;
do offset=0 to 120 by 30;
if first.cnum then sum=0;
if tdate le (ndate-offset) then sum+shares;
if last.cnum then output;
end;
run;
proc print ;
var cnum offset sum;
run;
If it does, then I have to ask, does your log show an error from the
statement: tdate=input(put(trandate,yymmdd8.),yymmdd8.); ?
If trandate is in yy/mm/dd form, but in text, then you would only need
tdate=input(trandate,yymmdd8.); to input tdate.
Art
---------
On Sat, 15 Oct 2005 16:29:44 -0400, Naser Khaledi <nkhaledi@AOL.COM> wrote:
>Hi all,
>
>I want to measure the number of shares sold in dataset “a” to the date
>(ndate) in dataset “b”. Dataset “a” date is tdate so I measure number of
>shares sold from tdate to ndate. Also, I change tdate in every run to 30,
>60, 120, etc. days prior to ndate. Below is the SAS code and it runs but I
>am not sure it sums the way I want it. I changed OFFSET from 0 to 30, 60,
>ect. and the result did not change. Appreciate your help.
>
>Naser,
>/**************** SAS code below ***************/
>
>libname w v8'~/';
>data new4;
> set w. insidernaser;
>cnum=cusip6;
>proc sort; by cnum;
>run;
>
>data a;
>length cnum $8;
>set new4;
>tdate=input(put(trandate,yymmdd8.),yymmdd8.);
>proc sort data=a; by cnum;
>
>data b;
>length cnum $8;
>infile 'handcollect_empty3.prn' truncover;
>input cnum $ 1-8 ticker $ 13-22 name1 $ 25-32 announce $ 33-42;
>
>ndate=input(announce,mmddyy10.);
>put announce= ndate=;
>run;
>proc sort data=b; by cnum;
>
>data c;
>merge a(in=in1) b(in=in2);
>by cnum;
>
>retain offset 0;
> set b; by cnum;
> sum=0;
> do point=1 to nobs;
> set a point=point nobs=nobs;
> if tdate le (ndate-offset) then sum+shares;
> else leave;
> end;
>run;
>proc print ; var cnum shares ;
>run;
>endsas;
|