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 (January 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 19 Jan 2007 09:28:15 -0500
Reply-To:     Amy Sun <tonyliang20032@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Amy Sun <tonyliang20032@GMAIL.COM>
Subject:      Re: generating page numbers
Comments: To: "data _null_," <datanull@gmail.com>
In-Reply-To:  <7367b4e20701190540r726f8515p180faba75f4873d8@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi, data _null_; It is amazing to your code, simple and efficient! Great to know that!

Thank you.

Amy

On 1/19/07, data _null_; <datanull@gmail.com> wrote: > > I don't know exactly what you are asking, but to obtain the data set > you show as "my expectation" the mod function is useful. Consider the > following example. > > data work.withPageVar30; > do trt = 1 to 3; > do obs = 1 to 40; > if mod(obs,30) eq 1 then page+1; > output; > end; > end; > run; > > proc report nowd headline headskip; > column page trt obs; > define page / order noprint; > break before page / page; > run; > quit; > > On 1/18/07, Amy Sun <tonyliang20032@gmail.com> wrote: > > Hi, all; > > > > I want to generate the page number for a dataset, there are several > > treatment groups: 1, 2, 3. I want the final dataset will have the page > > number information for each treatment, the following is my expectation: > > > > trt obs newobs page > > 1 1 1 1 > > ....... > > 1 30 30 1 > > 1 31 31 2 > > .... > > 1 40 40 2 > > > > 2 1 41 3 > > ....... > > 2 30 70 3 > > 2 31 71 4 > > .... > > 2 40 80 4 > > > > 3 1 81 5 > > ....... > > 3 30 110 5 > > 3 31 111 6 > > .... > > 3 40 120 6 > > > > I want to write a macro to present the above dataset, while something > should > > be wrong with my following code > > > > data page (drop = obs); > > do trt = 1 to 3; > > do obs = 1 to 40; > > output; > > end; > > end; > > run; > > > > %macro pager(dsin =, var =); > > %global num0 maxobs num1; > > > > proc sort data = &dsin; > > by &var; > > > > data pp; > > set &dsin; > > by &var; > > if first.&var then obs = 0; > > obs + 1; > > newobs + 1; > > > > proc sql; > > create table er as > > select *, ceil(max(obs)/30) as pagen > > from pp > > group by &var; > > quit; > > > > proc sort data = er; > > by &var obs; > > > > proc sql noprint; > > select pagen into : num0 > > from er > > where obs = newobs; > > select max(newobs) into : maxobs > > from er > > where obs = newobs; > > quit; > > > > data total; > > set er; > > by &var; > > if first.&var then output; > > > > proc sql noprint; > > select sum(pagen) into : totalpage > > from total; > > quit; > > > > data er (drop = i); > > set er end = eof; > > if obs = newobs then do; > > do i = 1 to &num0; > > if 30 * (i-1) < obs <= 30*i then page = i; > > end; > > end; > > if eof then stop; > > > > %do; > > proc sql noprint; > > select pagen into : pagea > > from er > > where page ne . ; > > quit; > > > > %do j = 1 %to &pagea; > > proc sql noprint; > > select max(newobs) into : num1 > > from er > > where page ne . ; > > > > data er; > > set er; > > if newobs - obs = &num1 then do; > > if 30 * %eval(&j-1) < obs <= 30*%eval(&j) then page = %eval(&num0 > + > > &j); > > end; > > %end; > > > > %end; > > > > proc sql noprint; > > select pagen into : num0 > > from er > > where page ne . ; > > select max(newobs) into : maxobs > > from er > > where page ne . ; > > quit; > > > > %mend; > > %pager(dsin = page, var = trt); > > proc print data = er; > > run; > > > > please take a look at my code. Thanks in advance for your suggestions. > > > > Best regards, > > Amy > > >


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