Naz
Naz

Reputation: 91

Transposing one column in a dataset but by year and another column

enter image description hereI have this dataset here which looks like this:

Basically I want to manipulate the data set so that I have GVKEY1 as unique such as 1004 then a unique year number such as 1996 then several gvkey2 after that. However the number of gvkey2 for each year is not the same. Does anyone know how to get around this problem? This means I will have several 12 lines of data for gvkey1 for 1004 since i have years from 1996 to 2008. Then for each year I will have many columns where each column will have a gvkey2.

Best Regards,

Naz

Upvotes: 0

Views: 710

Answers (2)

DavB
DavB

Reputation: 1696

Can you not just use PROC TRANSPOSE?

proc sort data=your_data_set out=temp1;
  by gvkey1 year;
run;

proc transpose data=temp1 out=temp2;
  by gvkey1 year;
  var gvkey2;
run;

This will give you a series of variables COL1 - COLx. Use the PREFIX option for different variable names.

Upvotes: 3

itzy
itzy

Reputation: 11765

I'm not sure I've understood your question, but if you're looking for unique gvkey1/year pairs, you could do either of these:

proc sql;
 create table results as
 select distinct gvkey1, year
 from _your_data_set;
quit;

or

proc sort data=_your_data_set(keep=gvkey1 year) out=results nodupkey;
 by gvkey1 year;
run;

If that's not what you're looking for, I suggest posting an example of the results you want.

Upvotes: 0

Related Questions