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

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

Astounding
PROC Star

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 1143 views
  • 0 likes
  • 3 in conversation