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
>complicated.
>
>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 =
>0;
>
>And stop inputting record when I encounter this following record:
> if Category_name = 'Multi-category Commerce' AND
>SUBCATEGORY_NAME =
>'\' 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.
>
>Thanks~!
hi, denisu.pong,
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.
cheers,
chang
/* an example data */
data master;
do i = 1 to 10;
output;
end;
run;
/* extract 4 to 6 only */
data extract;
drop output;
retain output 0;
set master;
if not output then do;
if i = 4 then do;
output;
output = 1;
end;
end; else do; /* output = 1 */
if i = 7 then do;
output = 0;
end; else do;
output;
end;
end;
run;
/* check */
proc print data=extract;
run;
/* on lst
Obs i
1 4
2 5
3 6
*/