BookmarkSubscribeRSS Feed
Ishor
Calcite | Level 5

I have following data. I would really appreciate if you can help me to get weekly number of deaths by age group across the years. 

 

date_of_death  age_cat

2012-08-16         1

2012-08-27         2

2013-08-29         3

2019-07-21         4

 

I want the following. 

 

Year    week  deaths_count

2012    1        4

2012    2        2

2013    1        3

2013    2        6

.

2013    52       10

.

.

2019    1        2

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Your desired output does not contain age_cat. Please explain.

--
Paige Miller
Ishor
Calcite | Level 5

Thanks for the quick response, i have four age groups: 1, 2, 3, 4

 

date_of_death  age_cat

2012-08-16         1

2012-08-27         2

2013-08-29         3

2019-07-21         4

 

I want the following. 

 

Year    week  deaths_count  age_cat

2012    1        4                         1

2012    2        2                         2

2013    1        3                        1

2013    2        6                         1

.

2013    52       10                      3

.

.

2019    1        2

PaigeMiller
Diamond | Level 26

So, please don't make us guess or assume. Give us a complete description of the problem and a complete description or example of what you want.

 

Your first row in the output table is

 

Year    week  deaths_count  age_cat

2012    1        4                         1

 

Could your real data also have rows in the output that looks like this?

 

Year    week  deaths_count  age_cat

2012    1        7                         2

2012    1        1                         3

 

 

Also, is date_of_death a numeric variable or a character variable?

--
Paige Miller
Ishor
Calcite | Level 5

Thank you again,

I am looking an output table in the following format. Also, date_of_death is in numeric format

Year    week  deaths_count  age_cat

2012    1         20                         1

2012    2         18                         1

2012    3         16                         1

.           .           .                           .

.           .           .                           .

2012    52        10                        2

2012    1         20                         2

2012    2         18                         2

2012    3         16                         2

.           .           .                           .

.           .           .                           .

2012    52        10                        2

2013    1          20                        1

2013    2         18                         1

2013    3         16                         1

.           .           .                           .

.           .           .                           .

2013    52        10                        1

PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */
proc freq data=have;
    tables date_of_death*agecat/list;
    format date_of_death yyweeku7.;
run;
--
Paige Miller
Ishor
Calcite | Level 5

Thank you so much, it did work.  I am wondering if it is possible to get the output table in the following format. Sorry, i am a naive user

 

Year    week  deaths_count  age_cat

2012    1         20                         1

2012    2         18                         1

2012    3         16                         1

.           .           .                           .

.           .           .                           .

2012    52        10                        2

2012    1         20                         2

2012    2         18                         2

2012    3         16                         2

.           .           .                           .

.           .           .                           .

2012    52        10                        2

2013    1          20                        1

2013    2         18                         1

2013    3         16                         1

.           .           .                           .

.           .           .                           .

2013    52        10                        1

PaigeMiller
Diamond | Level 26

What is it specifically that you want to change from the output of my program? 

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 660 views
  • 0 likes
  • 2 in conversation