BookmarkSubscribeRSS Feed
Kim2009
Calcite | Level 5

Hello - 

 

I need help with the array below. I have several variables of interest which I’ve listed out. I want to count the number of visits that are acute care (ED or Hospital) and the number of visits that are not acute care (e.g., Dermatology, Podiatry, Physical Therapy). The 910 patients have a different number of visits. I need to base the 2 count variables on these conditions: if visit is not missing and visit is complete then count as Acute or Other. Right now, my code counts all Acute visits (viz_EDHosp_count) and all other non-Acute visits (viz_Other_count) regardless if the visit is complete or not. Is there a way to adapt the code below to obtain an accurate number of visits for each of the count variables by including if Stat1-Stat125 is complete then count? Thank you so much for your time.

 

Variables of interest  

Urg1-Urg125: Visit urgency = Acute, Scheduled, Walk-in

Stat1-Stat125: Visit status = Complete, Cancel by Provider, Cancel by Patient, No Show

 

Array that I need help with

data y;

set x;

array _u (*) viz1 – viz125;

do _n_ =1 to dim(_u);

if ^ missing(_u[_n_]) then do;

viz_EDHosp_count=sum(viz_EDHosp_count,(_u(_n_)="Acute")); /*To capture acute visits*/

viz_Other_count= sum(viz_Other_count,(_u(_n_) ^= "Acute")); /*To capture nonacute visits such as PT, walk-in to audiology clinic*/

end;

end;

run;

6 REPLIES 6
PaigeMiller
Diamond | Level 26

if visit is not missing and visit is complete then count as Acute or Other. Right now, my code counts all Acute visits (viz_EDHosp_count) and all other non-Acute visits (viz_Other_count) regardless if the visit is complete or not.

 

Define "visit is complete".

 

It would also help to show very small fake data, say 5 fake patients and 5 visits, and then show us what the result you want is for this fake data. Data should be provided as working SAS data step code which you can type in yourself or follow these instructions.

--
Paige Miller
Kim2009
Calcite | Level 5

Thank you for your reply Paige Miller. A visit is complete if the patient arrived to the appointment and the provider (or nurse in some instances) checked the patient out after the appointment ended or a discharged disposition in the case of an acute encounter (ED or Hospitalization) was available in the chart. I've included some fake data as requested and also have included the SAS code I used to obtain "Results generated by current code" (refer to table that contains the fake data). 

I appreciate any help you're able to provide. Thanks again. 

data y;

set x;

array _u (*) viz1 – viz125;

do _n_ =1 to dim(_u);

if ^ missing(_u[_n_]) then do;

viz_EDHosp_count=sum(viz_EDHosp_count,(_u(_n_)="Acute")); /*To capture acute visits*/

viz_Other_count= sum(viz_Other_count,(_u(_n_) ^= "Acute")); /*To capture nonacute visits such as PT, walk-in to audiology clinic*/

end;

end;

run;
                 Results generated by current code Results that I want 
id vizdate1type1urg1stat1vizdate2type2urg2stat2vizdate3 type3urg3stat3vizdate4type4urg4stat4viz_EDHosp_countviz_Other_countviz_EDHosp_countviz_Other_count
17/1/2019EDacute complete8/14/2019ear_nose_throatscheduled complete 6/10/2019Hospital acute complete     2121
25/1/2020Podiatry walk-incomplete 3/8/2020Psychunscheduled complete     9/10/2019ED acute complete 1212
32/22/2022Hospitalacute complete 3/16/2022Hospitalacute complete 5/6/2022Cardiology scheduled Noshow 7/1/2022endocrinology scheduled complete 2221
43/23/2020ED acute complete 4/18/2020PT scheduled complete 5/16/2020OT scheduled Canceled by provider 5/16/2020PTscheduled Noshow1311
5    12/13/2020Audiology scheduled Canceled by patient 8/12/2020Audiology scheduled Noshow 9/17/2020ED acute complete 1210

 

 



Kim2009
Calcite | Level 5

Correcting how data are displayed in the last 4 columns of the table with the fake data. My apologies for the formatting error. Thanks again. 

 

Results generated by current code                                         Results that I need 

id      viz_EDHosp_count     viz_Other_count                 viz_EDHosp_count     viz_Other_count   

1           2                                     1                                           2                                1

2          1                                      2                                           1                                2

3          2                                      2                                           2                                1

4          1                                      3                                           1                                1

5          1                                      2                                           1                                0

mkeintz
PROC Star

If you've tried the code you report, then please provide the corresponding log so that we can see what SAS said about your code.

 

And whether you've tried that code or not, please provide some sample data (only 5 or 6 visits should be sufficient), so that any code we offer can be pre-tested.

 

Help us help you.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PGStats
Opal | Level 21

If you can run that code without errors, you only seem to need to extend what you already did with

 

array _v (*) stat1 – stat125;
...
if ^ missing(_u[_n_]) and _v(_v[_n_]) = "Complete" then do;

PG
Kim2009
Calcite | Level 5

Thanks for your help. The code I shared on the forum runs without producing an error message. I will add what you've provided to my code when I return to work next week. I'll let you know if it works. Thanks again. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 901 views
  • 0 likes
  • 4 in conversation