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;
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.
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 | vizdate1 | type1 | urg1 | stat1 | vizdate2 | type2 | urg2 | stat2 | vizdate3 | type3 | urg3 | stat3 | vizdate4 | type4 | urg4 | stat4 | viz_EDHosp_count | viz_Other_count | viz_EDHosp_count | viz_Other_count |
1 | 7/1/2019 | ED | acute | complete | 8/14/2019 | ear_nose_throat | scheduled | complete | 6/10/2019 | Hospital | acute | complete | 2 | 1 | 2 | 1 | ||||
2 | 5/1/2020 | Podiatry | walk-in | complete | 3/8/2020 | Psych | unscheduled | complete | 9/10/2019 | ED | acute | complete | 1 | 2 | 1 | 2 | ||||
3 | 2/22/2022 | Hospital | acute | complete | 3/16/2022 | Hospital | acute | complete | 5/6/2022 | Cardiology | scheduled | Noshow | 7/1/2022 | endocrinology | scheduled | complete | 2 | 2 | 2 | 1 |
4 | 3/23/2020 | ED | acute | complete | 4/18/2020 | PT | scheduled | complete | 5/16/2020 | OT | scheduled | Canceled by provider | 5/16/2020 | PT | scheduled | Noshow | 1 | 3 | 1 | 1 |
5 | 12/13/2020 | Audiology | scheduled | Canceled by patient | 8/12/2020 | Audiology | scheduled | Noshow | 9/17/2020 | ED | acute | complete | 1 | 2 | 1 | 0 |
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
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.
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;
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.