I am trying to achieve the following transpose?
level | exposure | |
2008 | Construction | 276 |
2009 | Construction | 882 |
2010 | Construction | 929 |
2011 | Construction | 140 |
2012 | Construction | 330 |
2008 | Warehouse | 265 |
2009 | Warehouse | 750 |
2010 | Warehouse | 207 |
2011 | Warehouse | 169 |
2012 | Warehouse | 942 |
2008 | Manufacturing | 307 |
2009 | Manufacturing | 735 |
2010 | Manufacturing | 644 |
2011 | Manufacturing | 625 |
2012 | Manufacturing | 699 |
2008 | Distribution | 644 |
2009 | Distribution | 794 |
2010 | Distribution | 367 |
2011 | Distribution | 791 |
2012 | Distribution | 672 |
2008 | Construction | 98 |
2009 | Construction | 95 |
2010 | Construction | 163 |
2011 | Construction | 607 |
2012 | Construction | 62 |
2008 | Warehouse | 613 |
2009 | Warehouse | 322 |
2010 | Warehouse | 817 |
2011 | Warehouse | 819 |
2012 | Warehouse | 723 |
2008 | Manufacturing | 380 |
2009 | Manufacturing | 861 |
2010 | Manufacturing | 140 |
2011 | Manufacturing | 144 |
2012 | Manufacturing | 564 |
2008 | Distribution | 282 |
2009 | Distribution | 407 |
2010 | Distribution | 830 |
2011 | Distribution | 841 |
2012 | Distribution | 524 |
to
Construction | Warehouse | Manufacturing | Distribution | |
2008 | 374 | ... | ... | ... |
2009 | 977 | ... | ... | ... |
2010 | 1092 | ... | ... | ... |
2011 | 747 | ... | ... | ... |
2012 | 392 | ... | ... | ... |
Any ideas how this can be done?
Where does the result of 374 come from? That can't be obtained by transposing.
Looks more like a report than a transpose.
proc freq ;
weight exposure;
tables yr*level ;
run;
Or, if you need the transposed dataset, just add an OUT option to Tom's suggested code and transpose the output file. e.g.:
proc freq data=have;
weight exposure;
tables year*level/out=need;
run;
proc transpose data=need out=want (drop=_:);
by year;
id level;
var count;
run;
I offer this, but as Paige stated don’t see where 374 come from in your new dataset.
Proc sort; by year level;
Data new; set; by year level;
If level=:’Cons’ then cons=exposure;
If level=:’Manu’ then manu=exposure;
If level=:;Distri’ the distr=exposure;
If level=:’Ware’ then ware=exposure;
Label cons= ‘Construction’ manu=’Manufacturing’
distr=”Distribution’ ware=’Warehouse;
if last.year the output; drop level exposure;
run;
proc print ; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.