DATA Step, Macro, Functions and more

How do I modify proc summary output to create a table

Reply
New User
Posts: 1

How do I modify proc summary output to create a table

Good morning,

 

I am trying to create 3 year moving average rates from a large birth file. I have used proc summary to get the data into a format to create the rates by year 

proc summary data=ptm_denom;
  class year;
  var preterm birth;
  output out=ptmtab sum=preterm birth;
  run;
  proc print data=ptmtab;
  run;
  data ptm_rate (drop = _type_ _freq_);
  set ptmtab;
  ptmrate = (preterm/birth)*100;
  run;
proc print data=ptm_rate noobs;
var year preterm birth ptmrate;
run;

 

And my output looks like this:

year preterm birth ptmrate

.3986520257.66170
200743955497.91134
200845356278.05047
200945355178.21098
201045352988.55040
201139450827.75285
201236350697.16118
201336849467.44036
201437450317.43391
201532849776.59032
201636149297.32400

 

but I can't figure out how to sum and average the data and manipulate the table so my output looks like this:

 

 2007-20092008-20102009-20112010-20122011-20132012-20142013-20152014-2016
preterm        
birth        
ptmrate        

 

This seems like there would be an easy solution, but I can't figure one out. Any help would be great!

Respected Advisor
Posts: 2,825

Re: How do I modify proc summary output to create a table

PROC EXPAND (if you have it in your SAS license) can provide 3 year moving averages of your data.

 

Since your output is vertical but the table you want is horizontal, you could transpose your output, then use ARRAYs in a data step to get three year moving averages.

 

But just a word to the wise ... keep your final table vertical, not horizontal, it's a much easier format for SAS to work with, and much easier for people to read.

--
Paige Miller
Ask a Question
Discussion stats
  • 1 reply
  • 64 views
  • 0 likes
  • 2 in conversation