If you are only interested in the number of visits and the number of patients who have that visits, then Proc SQL also has approach: (raw data stoled from PG's post):
data visits;
length patient visit $10;
infile datalines missover;
input patient visit @;
do while (not missing(visit));
output;
input visit @;
end;
datalines;
patientA clinic1 clinic2 clinic3 clinic1 clinic4 clinic1
PatientB clinic2 clinic3 clinic1 clinic2 clinic2
PatientC clinic1 clinic3 clinic1 clinic2 clinic2
;
proc sql;
select ct as visits, count(*) as patient_num from
(select count(*) as ct from visits group by patient)
group by ct;
quit;
Haikuo
Haikuo-
PROC SQL command seemed to have worked. I gave an example for January, however, I am interested in getting counts for the remaining months. Can you help me with the SQL coding on where I should include the variable 'month' to produce similar counts for each month?
Thank you
proc sql;
select month, ct as visits, count(*) as patient_num from
(select count(*) as ct, month from visits group by month,patient)
group by month,ct;
quit;
Not tested.
Haikuo
Probably more elegant ways but:
data have;
length month patient visit $10;
infile datalines missover;
input month patient visit @;
do while (not missing(visit));
output;
input visit @;
end;
datalines;
January patientA clinic1 clinic2
January PatientB clinic2 clinic3 clinic1 clinic2 clinic2
January PatientC clinic1 clinic3 clinic1 clinic2 clinic2 clinic3
February patientA clinic1 clinic2 clinic3 clinic1 clinic4 clinic1
February PatientB clinic2 clinic3 clinic1 clinic2 clinic2
February PatientC clinic1 clinic3 clinic1 clinic2 clinic2
;
proc summary noprint nway n
data = have ;
class month patient ;
output out = tmp_want (
drop = _type_
rename = (_freq_ = visits)) ;
run ;
proc summary noprint nway n
data = tmp_want ;
class month visits ;
output out = want (
drop = _type_
rename = (_freq_ = patients)) ;
run ;
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.