LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 7 Sep 2008 16:28:26 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>"
              <schreier.junk.mail@GMAIL.COM>
Subject:      Re: Array question

On Thu, 4 Sep 2008 10:55:52 -0500, yingtao <yingtaoliu@GMAIL.COM> wrote:

>data have ; >input PT day day2 ; >cards ; >1 10 20 >1 11 21 >1 12 22 >2 13 23 >2 14 24 >; > >data b; >do until(last.pt); >set have; >by pt; >rank=sum(rank,1); >end; >run;

The DO statement can do a little more of the work:

data b; do rank = 1 by 1 until(last.pt); set have; by pt; end; run;

The DATA step can do even more of the work, eliminating the need for the SQL:

data _null_; do rank = 1 by 1 until(last.pt); set have end=lastobs; by pt; end; retain mxnum; mxnum = max(mxnum,rank); if lastobs then call symput( 'mxnum' , strip( put( mxnum , 8. ) ) ); run;

Or, as others have suggested, the DATA step can be omitted and SQL can construct the macro variable by itself:

proc sql noprint; select strip ( put ( max(rank) , 2. ) ) into : mxnum from ( select count(*) as rank from have group by pt ) ; quit;

> >proc sql; >select strip(put(max(rank),2.-L)) into:mxnum >from b; >quit; > > >data need(drop=day day2 i) ; >length pt 3 ; > array day_[&mxnum.] ; > array day2_[&mxnum.] ; > do i=1 by 1 until( last.pt ) ; > set have ; > by pt ; > day_[i]=day ; > day2_[i]=day2 ; > end ; > run ;


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