LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 18 Nov 2004 04:44:35 -0800
Reply-To:     Dennis Diskin <diskin@SNET.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dennis Diskin <diskin@SNET.NET>
Subject:      Re: FIRST. / LAST. Processing with Arrays
Comments: To: m n <iced_phoenix_news@YAHOO.COM>
In-Reply-To:  <20041117225250.43308.qmail@web52805.mail.yahoo.com>
Content-Type: text/plain; charset=us-ascii

Matt,

One way would be to build a temporary array holding to hold the values fof first.key[i] and populate it vis a macro loop. Not very efficient if you are deling with large files.

example:

%macro first(N=N,first=first,key=key); %local i; array &first(&N) _temporary_; %do i = 1 %to &N; &first.&i = first.&key.&i; %end; %mend first;

data blah; set mydata; by key1-key&N; %first;

/* then use the first array as you would have used first.key[n] */

do i = 1 to &n; if first(i) then do whatever; end; end;

HTH, Dennis Diskin

m n <iced_phoenix_news@YAHOO.COM> wrote: SAS-L,

Consider the following code (assume mydata is properly sorted on by-variables, N is defined, etc):

data blah; set mydata; by key1-key&N;

array key[&N];

do I=1 to &N; if first.key[I] then do; /* something */ end; end; run;

Clearly, the "first.key[I]" is not syntactically valid in SAS, but is it possible to achieve the intended effect without resorting to a macro array/loop such as:

%do I=1 %to &N; if first.key&I then do; /* something */ end; %end;

Thanks for your help! Matt

__________________________________ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com


Back to: Top of message | Previous page | Main SAS-L page