From: rangoon rangoon on
Hi all,

I have data mm. i want to create a new dataset(want) such that for
each abc category if ST is missing it should be added with its
corresponding NT.

(example in data mm --- for abc category 2 there are only two records
(ST has distinct values of 1, 2, 3)
1 123 2
2 234 2
but in data want the missing ST which is 3 is added with corresponding
NT
123 1 2
234 2 2
345 3 2
)

i can do in proc sql but i would appreciate if it can be done in data
step.

data mm;
input st nt abc;
datalines;
1 123 1
2 234 1
3 345 1
1 123 2
2 234 2
3 345 3
2 345 4
2 345 5
3 345 5
;
run;


data want;
NT ST ABC
123 1 1
234 2 1
345 3 1
123 1 2
234 2 2
345 3 2
123 1 3
234 2 3
345 3 3
123 1 4
234 2 4
345 3 4
123 1 5
234 2 5
345 3 5


Thanks.
Rang
From: Barry Schwarz on
Where does the corresponding NT come from. Is it the observation from
the preceding ABC group with the corresponding ST?

If so, sort by ABC and ST.

In the following data step, as each observation is read, confirm that
the value of ST is the expected one. If so, save the NT value in a
retained variable. If not, save the current observation in some
temporary variables, create a new observation with the desired values,
output it, restore the observation variables, and repeat starting at
the confirm step.

On Wed, 26 May 2010 07:42:04 -0700 (PDT), rangoon rangoon
<rangoonraja999(a)gmail.com> wrote:

>Hi all,
>
>I have data mm. i want to create a new dataset(want) such that for
>each abc category if ST is missing it should be added with its
>corresponding NT.
>
>(example in data mm --- for abc category 2 there are only two records
>(ST has distinct values of 1, 2, 3)
> 1 123 2
> 2 234 2
>but in data want the missing ST which is 3 is added with corresponding
>NT
> 123 1 2
> 234 2 2
> 345 3 2
>)
>
>i can do in proc sql but i would appreciate if it can be done in data
>step.
>
>data mm;
> input st nt abc;
> datalines;
> 1 123 1
> 2 234 1
> 3 345 1
> 1 123 2
> 2 234 2
> 3 345 3
> 2 345 4
> 2 345 5
> 3 345 5
> ;
>run;
>
>
>data want;
> NT ST ABC
> 123 1 1
> 234 2 1
> 345 3 1
> 123 1 2
> 234 2 2
> 345 3 2
> 123 1 3
> 234 2 3
> 345 3 3
> 123 1 4
> 234 2 4
> 345 3 4
> 123 1 5
> 234 2 5
> 345 3 5
>
>
>Thanks.
>Rang

--
Remove del for email