BookmarkSubscribeRSS Feed
slivingston1
Calcite | Level 5
Good morning,

I am trying to code for a situation I have never seen before.
I am trying to display a frequency table of different facilities and the amount of physical restraints used divided by types. IE>

(Facility ID) (Restr 1) (Restr 2)
1 42 35
2 342 32
3 23423 343

Each row is considered an admission to the facility, having a patient SSN attached to it. I also need to determine how many patients per restraint per facility. This would be determined by how many different social security numbers per restraint per facility ID , and somehow doing a count function.
The data is similar to this….

(Facility ID) ( SSN) ( Restr 1) (Restr 2)
1 1233 1 0
1 1233 1 0
1 1554 0 1
2 1111 1 0
2 1224 0 1
2 1224 0 1
Legend: restraint1=0, no restraint used, restraint 1=1, restraint used

I want a table to be generated from the above sample data to look like this…

(Facility ID) (Restr1) (# of Patients used restr1) (Restr 2) (# of Patients used restr2)
1 2 1 1 1
2 1 1 2 1

I am using enterprise as well. I suppose it has something to do with DupOUT but I am not as familiar with that function. Any help would be greatly appreciated!
1 REPLY 1
Dale
Pyrite | Level 9
Data step code could certainly construct the frequencies which you need.

proc sort data=mydata;
  by facilityID SSN;
run;

data freqs;
  set mydata;
  by facilityID ssn;
  if first.facilityID then do;
    NRestr1=0;        /* Number of times restraint 1 used */
    NPatRestr1=0;   /*Number of patients for whom restraint 1 was used */

    NRestr2=0;        /* Number of times restraint 2 used */
    NPatRestr2=0;   /*Number of patients for whom restraint 2 was used */

    ...
  end;

  if first.SSN then do;
    PatRestr1=0;   /* Restraint 1 ever used on patient */
    PatRestr2=0;   /* Restraint 2 ever used on patient */
    ...
  end;

  NRestr1 + Restr1;   /* Increment total use of restraint 1 */
  NRestr2 + Restr2;   /* Increment total use of restraint 2 */
  ...

  PatRestr1 = max(PatRestr1, Restr1);   /* Update indicator of patient ever using restraint 1 */
  PatRestr2 = max(PatRestr2, Restr2);   /* Update indicator of patient ever using restraint 2 */
  ...

  if last.SSN then do;
    NPatRestr1 + PatRestr1;   /* Increment count of patients using restraint 1 */
    NPatRestr2 + PatRestr2;   /* Increment count of patients using restraint 2 */
    ...
  end;

  if last.FacilityID then output;
  keep facilityID NRestr1 NpatRestr1 NRestr2 NpatRestr2;
run;

proc print data=freqs;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1071 views
  • 0 likes
  • 2 in conversation