Summing Across Records

If the unit of analysis, say census tracts or zip codes, is broken into parts for some tracts or zip codes, these parts need to be combined if the unit of analysis is the census tract or zip code. For example, one might have the following data:

Tract    # of persons
1111        45
1111        50
2222        33
3333        15
3333        26
3333        31

For analysis purposes, the user needs the data to look like this:

Tract   # of persons
1111        95
2222        33
3333        72

The following program sums across IDs and then deletes all but one record per ID.

data a;
infile '/usr/work/gli/test.dat';
input id a;
proc sort data=a; by id;
run;
proc means noprint data=a;
by id;
var a;
output out=sum sum(a)=ax;
run;
data new;
   merge a sum(keep=id ax);
run;
proc print;
var id a ax;
proc sort nodupkey; by id;
proc print;
var id ax;
run;

NEW PSC blog

Recent resources, events, news

New Publications

Knodel et al. "Gendered Housework in Vietnam." PSC Research Report.

Couper. Designing Effective Web Surveys

Next Brown Bag

Monday, Oct 13
Jamie Jones
"Fertility & Risk Aversion on Utah Frontier"


W A R N I N G

If you are reading this, it may be that you are using rather old web browsing software that does not support modern international Web technology standards. For a better experience of the Web and this site in particular, please upgrade your web browser software today. The following are good choices: Firefox 2; Opera 9; Safari 3.