DATA Step, Macro, Functions and more

how to create this new data set?

Reply
N/A
Posts: 0

how to create this new data set?

Hi,

I need help to do the following: I have a data set in this form:
ID F G
1 x a
1 y b
1 z c
2 x d
2 y e
2 z f
3 x g
3 y h
3 z i

Now I want to have the following data set:
ID x y z
1 a b c
2 d e f
3 g h i

How to do it? Thanks. Message was edited by: firephoenix
SAS Super FREQ
Posts: 8,743

Re: how to create this new data set?

Hi,
Let's assume that your dataset is called WORK.MYDATA and that it has the 3 variables that you showed. This PROC TRANSPOSE step would create a dataset in the form that you wanted. The only thing you might have to do is delete the automatic variable _NAME_ that PROC TRANSPOSE creates.
[pre]
proc transpose data=mydata out=d_trans;
by id;
id f;
var g;
run;

options nocenter;
proc print data=d_trans;
title 'transposed data';
run;

[/pre]

And the results would be:
[pre]
transposed data

Obs id _NAME_ x y z

1 1 g a b c
2 2 g d e f
3 3 g g h i

[/pre]

For more help with PROC TRANSPOSE, you might consider reading the documentation on PROC TRANSPOSE and/or contacting Tech Support.

cynthia
N/A
Posts: 0

Re: how to create this new data set?

Thank you very much.
Ask a Question
Discussion stats
  • 2 replies
  • 127 views
  • 0 likes
  • 2 in conversation