BookmarkSubscribeRSS Feed
JenMMerc
Fluorite | Level 6

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!

1 REPLY 1
PaigeMiller
Diamond | Level 26

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 598 views
  • 0 likes
  • 2 in conversation