Hi
I have data like the following:
| quarter | area | naics | agegrp | hires | |
| 2001 | 1 | 1 | 11 | 1 | 604 |
| 2001 | 1year | 1 | 11 | 2 | 416 |
| 2001 | 1 | 89 | 11 | 1 | 55 |
| 2001 | 1 | 89 | 11 | 2 | 86 |
| 2001 | 1 | 1 | 51 | 1 | 203 |
| 2001 | 1 | 1 | 51 | 2 | 143 |
| 2001 | 1 | 89 | 51 | 1 | 12 |
| 2001 | 1 | 89 | 51 | 2 | 8 |
| 2001 | 2 | 1 | 11 | 1 | 300 |
| 2001 | 2 | 1 | 11 | 2 | 256 |
| 2001 | 2 | 89 | 11 | 1 | 45 |
| 2001 | 2 | 89 | 11 | 2 | 67 |
| 2001 | 2 | 1 | 51 | 1 | 56 |
| 2001 | 2 | 1 | 51 | 2 | 76 |
| 2001 | 2 | 89 | 51 | 1 | 12 |
| 2001 | 2 | 89 | 51 | 2 | 7 |
| 2001 | 3 | 1 | 11 | 1 | 412 |
| 2001 | 3 | 1 | 11 | 2 | 365 |
| 2001 | 3 | 89 | 11 | 1 | 42 |
| 2001 | 3 | 89 | 11 | 2 | 56 |
| 2001 | 3 | 1 | 51 | 1 | 532 |
| 2001 | 3 | 1 | 51 | 2 | 432 |
| 2001 | 3 | 89 | 51 | 1 | 34 |
| 2001 | 3 | 89 | 51 | 2 | 12 |
I am trying to create something like:
| year | quarter | naics | hiresN |
| 2001 | 1 | 11 | 1161 |
| 2001 | 1 | 51 | 366 |
| 2001 | 2 | 11 | 668 |
| 2001 | 2 | 51 | 151 |
| 2001 | 3 | 11 | 875 |
| 2001 | 3 | 51 | 1010 |
where hiresN is the sum of hires in the first data set over counties and age groups
How could I code this?
You could use:
proc summary data=have nway;
class year quarter naics;
var hires;
output out=want sum=hiresN;
run;
HTH,
Art
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.