Reputation: 171
I have the following Dataset:
Date Occupation Employment
01/01/2005 1 Management
01/01/2005 1 Management
01/01/2005 1 Science
01/01/2006 1 Science
05/01/2006 1 Operational
01/01/2006 1 Science
for each month and year from January 2005 until December 2015.
What I want is Total for each category of the variable Employment for each month and year.
So for the example above it would be something like the following:
Date Occupation_Total Employment
01/01/2005 2 Management
01/01/2005 1 Science
01/01/2006 2 Science
01/01/2006 1 Operational
What is the best way to go about accomplishing this?
Upvotes: 0
Views: 66
Reputation: 21264
This is generating summary statistics by a group. Proc Means or Proc Freq are appropriate. I'll demo proc means in case not all Occupation have a value of 1.
proc means data=have nway;
class date employment;
format date yymon7.;
var occupation;
output out=want sum(occupation)=total_occupation p25(occupation)=occupation_p25;
run;
proc print;
run;
Upvotes: 2
Reputation: 409
You have to group data by using operator
If first.Employment .... If last.Employment....
Here is the explanation for this operators, it helps to group data then use sum
http://www.pauldickman.com/teaching/sas/set_by.php
Upvotes: 0
Reputation: 335
In a data step, extract the month and year using the month and year functions. Create a key by concatenating the extracted months and years. Then you can use proc sql to summarize, try the following:
data ds;
set ds;
month=month(date);
year=year(date);
key=catx("_",month,year);
run;
Proc sql;
create table summary as
select employment,key,sum(occupation) as occupation_total
from ds
group by employment,key;
quit;
Hope this helps.
Upvotes: 2