BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hello guys,

I working on coding for cancer mortality and lung cancer deaths. My code is shown below.

In the code, I want rdeath to represent the death rate per 10,000 person-years (PY). and rcancerdeath and rlungdeath to  represent the cancer and lung cancer death rate per 10,000PY respectively. I've struggled to use an array and a do over for this. Can anyone help me check the code?

 

Data me; set sc_cancer_surveillance; 
Array ab   ndeath ncancerdeath nlungdeath ;
Array cd  rdeath rcancerdeath rlungdeath;
do over cd;
rdeath=ndeath/person_years;
rcancerdeath=ncancerdeath/person_years;
rlungdeath= nlungdeath/person_years;
end;
run;

Please see the initial table that I got and I want to calculate the rates in person-years,

 

 

Obs

Smoking

Person_years

Ndeath

Ncancerdeath

Nlungdeath

1

0

4200

900

150

39

2

1

5210

1100

200

12

1 ACCEPTED SOLUTION

Accepted Solutions
blueskyxyz
Lapis Lazuli | Level 10
sorry, please add semicolon in this row: rdeath=ndeath/person_years;

Data me;
input Smoking Person_years Ndeath Ncancerdeath Nlungdeath;
Array ab ndeath ncancerdeath nlungdeath ;
Array cd rdeath rcancerdeath rlungdeath;
do over cd;
rdeath=ndeath/person_years;
rcancerdeath=ncancerdeath/person_years;
rlungdeath=nlungdeath/person_years;
end;
cards;
0 4200 900 150 39
1 5210 1100 200 12
;
run;


View solution in original post

3 REPLIES 3
blueskyxyz
Lapis Lazuli | Level 10
Data me; 
    input Smoking	Person_years	Ndeath	Ncancerdeath	Nlungdeath;
    Array ab   ndeath ncancerdeath nlungdeath ;
    Array cd  rdeath rcancerdeath rlungdeath;
    do over cd;
        rdeath=ndeath/person_years
        rcancerdeath=ncancerdeath/person_years;
        rlungdeath=nlungdeath/person_years;
    end;
cards;
0      4200      900      150      39                                                                                                   
1      5210      1100      200      12 
;
run;
blueskyxyz
Lapis Lazuli | Level 10
sorry, please add semicolon in this row: rdeath=ndeath/person_years;

Data me;
input Smoking Person_years Ndeath Ncancerdeath Nlungdeath;
Array ab ndeath ncancerdeath nlungdeath ;
Array cd rdeath rcancerdeath rlungdeath;
do over cd;
rdeath=ndeath/person_years;
rcancerdeath=ncancerdeath/person_years;
rlungdeath=nlungdeath/person_years;
end;
cards;
0 4200 900 150 39
1 5210 1100 200 12
;
run;


sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 825 views
  • 0 likes
  • 2 in conversation