BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

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?

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Tom
Super User Tom
Super User

Looks more like a report than a transpose.

proc freq ;

  weight exposure;

  tables yr*level ;

run;

art297
Opal | Level 21

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;

Jim_G
Pyrite | Level 9

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 717 views
  • 0 likes
  • 6 in conversation