Hi all,
I have the following dataset,
RAW DATA
Var A | Agency # | ID # | Admission # | Service # | Service Type | Var Z |
AAA | 555 | 1 | 1 | 1 | Phamacotherapy | YYY |
AAA | 555 | 1 | 1 | 2 | Counseling | YYY |
AAA | 555 | 1 | 1 | 3 | Counseling | YYY |
BBB | 999 | 10 | 5 | 1 | Counseling | ZZZ |
BBB | 999 | 10 | 5 | 2 | Rehabilitative Care | ZZZ |
This dataset contains services utilized as part of admissions. Each admission is defined as the combination of Agency #, ID # and Admission #. I want to count the services utilized as part of each admission, and ascertain if pharmacotherapy services were utilized as a part of the admission. The desired output should be as follows,
DESIRED OUTPUT
Var A | Agency # | ID # | Admission # | Service # | Service Type | Var Z | Total # of Services Utilized in Admission | Pharmacotherapy Part of Admission |
AAA | 555 | 1 | 1 | 1 | Phamacotherapy | YYY | 3 | Yes |
AAA | 555 | 1 | 1 | 2 | Counseling | YYY | 3 | Yes |
AAA | 555 | 1 | 1 | 3 | Counseling | YYY | 3 | Yes |
BBB | 999 | 10 | 5 | 1 | Counseling | ZZZ | 2 | No |
BBB | 999 | 10 | 5 | 2 | Rehabilitative Care | ZZZ | 2 | No |
Any help would be much appreciated.
Thank you.
Since you do not provide a problem with variable names specified, the below is basically a logic outline of two phases:
data want;
/* Read and count all recs for an admission */
do totalsrv=1 by 1 until (last.admission);
set have;
by agency id admission;
if svt_type='Pharmacotherapy' then pharmpart='Yes';
end;
if Pharmpart^='Yes' then Pharmpart='No';
/* Reread and output */
do until (last.admission);
set have;
by agency id admission;
output;
end;
run;
Notes:
Since you do not provide a problem with variable names specified, the below is basically a logic outline of two phases:
data want;
/* Read and count all recs for an admission */
do totalsrv=1 by 1 until (last.admission);
set have;
by agency id admission;
if svt_type='Pharmacotherapy' then pharmpart='Yes';
end;
if Pharmpart^='Yes' then Pharmpart='No';
/* Reread and output */
do until (last.admission);
set have;
by agency id admission;
output;
end;
run;
Notes:
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.