Date: Thu, 13 Apr 2000 00:53:46 GMT
Reply-To: "Daniel J. Nordlund" <dnordlund@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Daniel J. Nordlund" <dnordlund@AOL.COM>
Organization: AOL http://www.aol.com
Subject: Re: help on basic sas programming
N Yiannakoulias <nwy@gpu.srv.ualberta.ca> wrote:
>Hello,
>
>Every time I run into a difficult programming task I
>usually abandon SAS in favour of a language that
>I am more familiar. In the long run however,
>I think this is costing me in overall efficiency.
>One programming element in SAS continues to confuse me:
>
>Here's are two sample data sets:
>
>id date v1 v2
>1 19970401 1 0
>2 19960326 0 1
>...
>
>id2 date2
>1 19960211
>1 19980611
>2 19970912
>2 19961201
>...
>
>My goal (in pseudo code)
>for each id in table 1
>{
> if id1 equals id2
> {
> if (date1 < date2)
> {
> write record to new file
> }
> }
>}
>
>In most languages I can simply compare elements in
>arrays and this is as easy as pie to program. I can't figure
>out how to do it in SAS. Part of the problem is that I never
>bought a book. Can anyone help me understand how to do this?
>
>N
>
How about something like the following. It assumes that the IDs are in sorted
order. If not, then sort the datasets first.
data one;
informat date yymmdd8.;
input id date v1 v2;
cards;
1 19970401 1 0
2 19960326 0 1
;
run;
data two;
informat date2 yymmdd8.;
input id2 date2;
cards;
1 19960211
1 19980611
2 19970912
2 19961201
;
run;
data three;
merge one two(rename=(id2=id));
by id;
if date<date2;
run;
proc print data=three;
run;
Hope this helps,
Dan Nordlund
|