Community talk about communities.sas.com. Meta!

Convert Quarterly data to Annual data

Reply
Senior User
Posts: 1

Convert Quarterly data to Annual data

Hi Guys, what code can i use to convert quarterly data to Annual data; Here is a sample of the data. You will notice some quarters in some years are missing. But ideally i want to have annual figures summed up from quarterly figures per year per "Accper".  I want to have totals for TOR and TOE in two new columns computed from adding up the different figures from the different quarters. 

 

StkcdAccperTORTOEyearmonthdayQuarter
131/12/1991334690000188230000199112314
131/12/1992475510800254612800199212314
130/06/1993266495500019936302
131/12/1993407870596.5114621987.4199312314
130/06/1994297087559.499154582.9319946302
131/12/1994662338768.2323169773.6199412314
130/06/1995415720836.9181933045.419956302
131/12/1995944990411.4480495603.7199512314
130/06/1996652159903.4274865660.919966302
131/12/19961261061632495232702.5199612314
130/06/1997650518641300511899.819976302
131/12/19971348895058733785961.5199712314
130/06/1998694283519.3330525163.819986302
131/12/199817581116581117254216199812314
130/06/1999498367080328570297.819996302
131/12/199914712206901119905523199912314
130/06/200056394265952451392220006302
131/12/200014312862641259262034200012314
130/06/200183651415476802407320016302
131/12/200121184413632035715964200112314
131/03/200259599831348961104720023311
130/06/20021315435885128900931520026302
130/09/20022120786642203508685320029303
131/12/200230770988473120449041200212314
131/03/200364996851665002813320033311
130/06/20031428220006143262488820036302
130/09/20032734822115283952789320039303
131/12/200331288362643482265794200312314
PROC Star
Posts: 326

Re: Convert Quarterly data to Annual data

may something like this might work.

 

proc sql;

select a.*, sum(TOR) as sum_tor, sum(TOE) as sum_toe from have

group by year, quarter;

quit;

Super User
Posts: 7,845

Re: Convert Quarterly data to Annual data

proc sql;
create table want as
select year, sum(TOR) as TOR, sum(TOE) as TOE
from have
group by year;
quit;

or

proc summary data=have;
class year;
var TOR TOE;
output
  out=want (drop=_type_ _freq_)
  sum(TOR)=TOR
  sum(TOE)=TOE
;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 2 replies
  • 131 views
  • 0 likes
  • 3 in conversation