Date: Wed, 24 Feb 1999 08:46:16 +0000
Reply-To: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Subject: Re: Question: BOM processing
In-Reply-To: <s6d2dc07.051@email.firsthealth.com>
I expect you will be able to use a simple-ish data step with by group
processing "descesnding".
If the dirname is not available with a variale for each of the 15
levels, each can be "scan"-ed with levl{i} = scan( dirname, i, '\' )
At the same time, when you have a change in dirname, control break level
can be identified (top down), using laglevl{i} = lag( levl{i} )
You would accumulate to the next level up at each control break.
>>> something like ( untested )
do i=16 to 0 by -1 while( laglevl{i} ne levl{i} );
tot{i-1} + tot{i}
output;
tot{i} =0;
end;
>>>
I know this sounds a bit more than "simple", but as it is achieved in a
straight pass through ordered data, I imagine this is likely to run a
lot faster than a recursive sql step.
In article <s6d2dc07.051@email.firsthealth.com>, Jack Hamilton
<JackHamilton@FIRSTHEALTH.COM> writes
>I have a question about processing hierarchical data, sometimes
>called "bill of materials" processing (even when it doesn't have
>anything to do with bills or materials).
>
>Here's an example. Suppose I have a dataset DIRSPACE:
>
> Var/Obs DIRNAME SPACE PARENT
> 1 C:\ 100
> 2 C:\TEMP 200 C:\
> 3 C:\TEMP\U 400 C:\TEMP
> 4 C:\TEMP2 800 C:\
>
>Directories can go down as far as 15 levels.
>
>I want an output dataset that looks like this:
>
> Var/Obs DIRNAME TOTSPACE
> 1 C:\ 1500
> 2 C:\TEMP 600
> 3 C:\TEMP\U 400
> 4 C:\TEMP2 800
>
>This is a fairly common problem. I think one of the
>specialized proc's (in SAS/OR?) handles it, but all we
>have is base SAS. Does anyone have suggestions for a
>general approach? SQL is preferred, but data step code
>is also welcome.
>
>
>
>
>--
>JackHamilton@FirstHealth.com
>West Sacramento, California
--
Peter Crawford
|