duplicate records data into single row

  • Follow


Hi ,
I have a dataset with records like

ID VI Var1 Var2 Var3
1   1    .      23      .
1   1   21      .       .
1   1    .        .
24

I want this to be in one row something like

ID VI Var1 Var2 Var3
1   1   21     23    24


Any suggestion on how to make this possible?

Appreciate your time and help.

Regards
Matt
0
Reply clinicalprogrammer.sas (2) 1/26/2010 5:03:16 PM

On Jan 26, 11:03=A0am, Sravan Varma <clinicalprogrammer....@gmail.com>
wrote:
> Hi ,
> I have a dataset with records like
>
> ID VI Var1 Var2 Var3
> 1 =A0 1 =A0 =A0. =A0 =A0 =A023 =A0 =A0 =A0.
> 1 =A0 1 =A0 21 =A0 =A0 =A0. =A0 =A0 =A0 .
> 1 =A0 1 =A0 =A0. =A0 =A0 =A0 =A0.
> 24
>
> I want this to be in one row something like
>
> ID VI Var1 Var2 Var3
> 1 =A0 1 =A0 21 =A0 =A0 23 =A0 =A024
>
> Any suggestion on how to make this possible?
>
> Appreciate your time and help.
>
> Regards
> Matt
UPDATE statement....

data have;
   input (ID VI)(:$1.) Var1-Var3;
   cards;
1   1    .      23      .
1   1   21      .       .
1   1    .        .  24
;;;;
   run;
data flat;
   update have(obs=3D0) have;
   by id vi;
   run;
proc print;
   run;
0
Reply data 1/26/2010 5:08:15 PM


On Jan 26, 12:08=A0pm, "data _null_;" <datan...@gmail.com> wrote:
> On Jan 26, 11:03=A0am, Sravan Varma <clinicalprogrammer....@gmail.com>
> wrote:
>
>
>
> > Hi ,
> > I have a dataset with records like
>
> > ID VI Var1 Var2 Var3
> > 1 =A0 1 =A0 =A0. =A0 =A0 =A023 =A0 =A0 =A0.
> > 1 =A0 1 =A0 21 =A0 =A0 =A0. =A0 =A0 =A0 .
> > 1 =A0 1 =A0 =A0. =A0 =A0 =A0 =A0.
> > 24
>
> > I want this to be in one row something like
>
> > ID VI Var1 Var2 Var3
> > 1 =A0 1 =A0 21 =A0 =A0 23 =A0 =A024
>
> > Any suggestion on how to make this possible?
>
> > Appreciate your time and help.
>
> > Regards
> > Matt
>
> UPDATE statement....
>
> data have;
> =A0 =A0input (ID VI)(:$1.) Var1-Var3;
> =A0 =A0cards;
> 1 =A0 1 =A0 =A0. =A0 =A0 =A023 =A0 =A0 =A0.
> 1 =A0 1 =A0 21 =A0 =A0 =A0. =A0 =A0 =A0 .
> 1 =A0 1 =A0 =A0. =A0 =A0 =A0 =A0. =A024
> ;;;;
> =A0 =A0run;
> data flat;
> =A0 =A0update have(obs=3D0) have;
> =A0 =A0by id vi;
> =A0 =A0run;
> proc print;
> =A0 =A0run;

Interesting to see this approach. I was expecting either a data step
or Proc Transpose ..... Thanks...

Matt
0
Reply Eddie 1/26/2010 7:37:55 PM

not just interesting, but elegant !!!

another way (not as elegant, but data need not be sorted by ID and VI) ...

data have;
input (ID VI)(:$1.) Var1-Var3;
cards;
1   1    .      23      .
1   1   21      .       .
1   1    .        .  24
;
run;

proc summary data=have nway;
class id vi;
var var1-var3;
output out=want (drop=_:) sum=;
run;

--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

> On Jan 26, 12:08 pm, "data _null_;" <datan...@gmail.com> wrote:
>> On Jan 26, 11:03 am, Sravan Varma <clinicalprogrammer....@gmail.com>
>> wrote:
>>
>>
>>
>> > Hi ,
>> > I have a dataset with records like
>>
>> > ID VI Var1 Var2 Var3
>> > 1   1    .      23      .
>> > 1   1   21      .       .
>> > 1   1    .        .
>> > 24
>>
>> > I want this to be in one row something like
>>
>> > ID VI Var1 Var2 Var3
>> > 1   1   21     23    24
>>
>> > Any suggestion on how to make this possible?
>>
>> > Appreciate your time and help.
>>
>> > Regards
>> > Matt
>>
>> UPDATE statement....
>>
>> data have;
>>    input (ID VI)(:$1.) Var1-Var3;
>>    cards;
>> 1   1    .      23      .
>> 1   1   21      .       .
>> 1   1    .        .  24
>> ;;;;
>>    run;
>> data flat;
>>    update have(obs=0) have;
>>    by id vi;
>>    run;
>> proc print;
>>    run;
>
> Interesting to see this approach. I was expecting either a data step
> or Proc Transpose ..... Thanks...
>
> Matt
>
0
Reply msz03 (782) 1/26/2010 8:19:00 PM

3 Replies
567 Views

(page loaded in 0.073 seconds)

Similiar Articles:













7/24/2012 7:50:29 PM


Reply: