Help using Base SAS procedures

Transposing

Reply
Super Contributor
Posts: 259

Transposing

I am trying to achieve the following transpose?

levelexposure
2008Construction276
2009Construction882
2010Construction929
2011Construction140
2012Construction330
2008Warehouse265
2009Warehouse750
2010Warehouse207
2011Warehouse169
2012Warehouse942
2008Manufacturing307
2009Manufacturing735
2010Manufacturing644
2011Manufacturing625
2012Manufacturing699
2008Distribution644
2009Distribution794
2010Distribution367
2011Distribution791
2012Distribution672
2008Construction98
2009Construction95
2010Construction163
2011Construction607
2012Construction62
2008Warehouse613
2009Warehouse322
2010Warehouse817
2011Warehouse819
2012Warehouse723
2008Manufacturing380
2009Manufacturing861
2010Manufacturing140
2011Manufacturing144
2012Manufacturing564
2008Distribution282
2009Distribution407
2010Distribution830
2011Distribution841
2012Distribution524

to

ConstructionWarehouseManufacturingDistribution
2008374.........
2009977.........
20101092.........
2011747.........
2012392.........

Any ideas how this can be done?

Super User
Posts: 17,824
Trusted Advisor
Posts: 1,615

Re: Transposing

Where does the result of 374 come from? That can't be obtained by transposing.

Super User
Super User
Posts: 6,500

Re: Transposing

Looks more like a report than a transpose.

proc freq ;

  weight exposure;

  tables yr*level ;

run;

PROC Star
Posts: 7,363

Re: Transposing

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=_Smiley Happy;

  by year;

  id level;

  var count;

run;

Frequent Contributor
Posts: 83

Re: Transposing

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;

Ask a Question
Discussion stats
  • 5 replies
  • 195 views
  • 0 likes
  • 6 in conversation