Date: Tue, 15 Aug 2006 13:41:11 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: Restricting to rows only complied to certain criteria
On Tue, 15 Aug 2006 10:17:41 -0700, denisu.pong@GMAIL.COM wrote:
>Here is a problem which I have. It looks simple but actually rather
>I have a data set that has variable number of rows each month. But the
>data set is pre-sorted by panel, category_name, subcategory_name,
>tree_name and rank.
>So what I want is really subset of this dataset starting at a specific
>row and ending at a specific row, which is dynamic every month.
>The problem with a "query in PROC SQL" or simply subsetting with
>"where" or "if" is there are always rows with exact same category_name,
>subcategory_name, and tree_name in different rows of the data set
>(which do have different rankings w.r.t. its section). So what I need
>to figure the following.
>Restrict to panel only to "work"
> if panel = "Work" ;
>Start inputting records only when I see the following record:
> if SUBCATEGORY_NAME = '\' AND TREE_NAME = 'Home &
>Fashion' AND RANK =
>And stop inputting record when I encounter this following record:
> if Category_name = 'Multi-category Commerce' AND
>'\' AND TREE_NAME = 'Multi-category Commerce' AND RANK = 0;
>I am thinking there might be a macro involved in this particular
>problem just to locate dynamically where the starting rows and ending
>rows are every month.
>Please let me know if there's an easy way out.
If you don't mind going through the data once, then it is straight-forward.
Here is a toy example. Hopefully this is essentially the same as what you
want to do, only the starting and ending conditions are more complicated in
your case. HTH.
/* an example data */
do i = 1 to 10;
/* extract 4 to 6 only */
retain output 0;
if not output then do;
if i = 4 then do;
output = 1;
end; else do; /* output = 1 */
if i = 7 then do;
output = 0;
end; else do;
/* check */
proc print data=extract;
/* on lst