DATA Step, Macro, Functions and more

creating variables by summing over conditional observations

Reply
Contributor
Posts: 33

creating variables by summing over conditional observations

Hi

I have data like the following:

quarterareanaicsagegrphires
200111111604
20011year1112416
200118911155
200118911286
200111511203
200111512143
200118951112
20011895128
200121111300
200121112256
200128911145
200128911267
20012151156
20012151276
200128951112
20012895127
200131111412
200131112365
200138911142
200138911256
200131511532
200131512432
200138951134
200138951212

I am trying to create something like:

yearquarternaicshiresN
20011111161
2001151366
2001211668
2001251151
2001311875
20013511010

where hiresN is the sum of hires in the first data set over counties and age groups

How could I code this?

PROC Star
Posts: 7,492

creating variables by summing over conditional observations

You could use:

proc summary data=have nway;

  class year quarter naics;

  var hires;

  output out=want sum=hiresN;

run;

HTH,

Art

Frequent Contributor
Posts: 75

Re: creating variables by summing over conditional observations

If you are familiar with PROC SQL then you can use that also.

PROC SQL;

   SELECT YEAR,QUARTER,NAICS,SUM(HIRES) AS HIRESN

   FROM NEWDS

   GROUP BY YEAR, QUARTER, NAICS;

QUIT;

Thanks

Dhanasekaran R

Ask a Question
Discussion stats
  • 2 replies
  • 158 views
  • 0 likes
  • 3 in conversation