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:
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.
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.