Hi! I need to create a count visits by patient and age. I have attempted with the following syntax, but age is not counting correctly
data util_sum;
set asthma.household_female;
by patientid patage;
if first.patientid=1 then N_util=0;
if utilization=1 then N_util +1;
if last.patientid=1 then output;
keep patientid patage n_util;
run;
I also tried using proc means, but age is still not counting correctly.
proc means sum data=utilization
by patientid;
class patage;
var utilization;
output out=var_sum sum=;
run;
Help is greatly appreciated!!
What is the definition of a "visit"? Is it any instance of utilization=1?
If so, your DATA step is very close. You refer to:
first.patientid
last.patientid
Instead, you should be referring to:
first.patage
last.patage
The PROC MEANS approach could work (assuming that you add the missing semicolon). But it would be safer to add a WHERE statement:
where utilization=1;
On the one hand, that would protect against suspect values for UTILIZATION such as 2 or -1. On the other hand, that would lead to further complications. You would no longer get totals of 0 as part of the output. It's probably safer to stick with the DATA step.
Please describe how "age is still not counting correctly".
You may need to decide which AGE to use for a count as your patients age increases between visits. So do you want
1) AGE at each visit and count each visit
2) Count age only at first visit
3) Count age only at latest visit
or something else?
Provide some example data and the desired result for that example.
What is the definition of a "visit"? Is it any instance of utilization=1?
If so, your DATA step is very close. You refer to:
first.patientid
last.patientid
Instead, you should be referring to:
first.patage
last.patage
The PROC MEANS approach could work (assuming that you add the missing semicolon). But it would be safer to add a WHERE statement:
where utilization=1;
On the one hand, that would protect against suspect values for UTILIZATION such as 2 or -1. On the other hand, that would lead to further complications. You would no longer get totals of 0 as part of the output. It's probably safer to stick with the DATA step.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.