I have patient encounter file with more than 13000 records. File structure is like this.
No Problemtype1 problemtype1b problemtype1c ... problemtype49 prblemtype49c outcome1 outcome1b ... outcome49c
--------------------------------------------------------------------------------------------------------------------------------------------------------------
1 aa bb cc aa bb solved rejected denied
2
...
13000
I need to count respective outcomes if problemtype is 'aa'. I am using following sample code.
data test2;
set testdata;
array problemType [4,3] ProblemType1 - ProblemType8 ProblemType1b1-ProblemType1b4;
array final_outcome {4,3} final_outcome1-final_outcome8 final_outcome1b1-final_outcome1b4;
aa=0;
Solved = 0;
Denied=0;
Rejected=0;
do i= 1 to 4;
do j=1 to 3;
if ProblemType(i,j) = 'aa' then aa=aa+ 1;
if ProblemType (i,j) = 'aa' then
if final_outcome (i,j) = 'resolved' then Solved = Solved + 1 ;
else if final_outcome (i,j) = Denied' then Denied=Denied+ 1;
else if final_outcome (i,j) = 'Rejected' then Rejected=Rejected + 1;
end;
end;
run;
This sample code works fine. But When I specify the following code while using it on original file having 13000 records
array problemType [13000,147] $;
array final_outcome {13000,147) $ ;
SAS goes into infinte loop. It does not produce any results.
Please help me with this problem. I am new to SAS.
Maybe your variable names are not exactly as you say and there is a name conflict... My code assumes that the list of problemType variables matches the list of outcome variables (same number and order).
Try using unrelated variable names to avoid conflict
data test2;
set testdata;
array pt{*} problemType:;
array o{*} outcome:;
do i = 1 to dim(pt);
cat = substr(vname(pt{i}), 12);
pType = pt{i};
outcm = o{i};
output;
end;
keep No cat pType outcm;
run;
proc sql;
create table counts as
select pType, outcm, count(*) as n
from test2
group by pType, outcm;
quit;
proc transpose data=counts;
where pType = "aa";
var n;
id outcm;
run;
You are mixing the array declaration and array usage with 3 types(like ( ), [ ], { }). Better to stick to one usage. I usually stay with [ ].
I am not sure whether my suggestion will fix your problem.
I also tried using []. It does not change output. Thanks for reply.
You can avoid a lot of trouble by first transforming your data into long form:
data test2;
set testdata;
array pt{*} problemType:;
array o{*} outcome:;
do i = 1 to dim(pt);
cat = substr(vname(pt{i}), 12);
problemType = pt{i};
outcome = o{i};
output;
end;
keep No cat problemType outcome;
run;
then use SQL to summarize:
proc sql;
create table counts as
select problemType, outcome, count(*) as n
from test2
group by problemType, outcome;
quit;
and subset and reshape to suit your needs:
proc transpose data=counts;
where problemType = "aa";
var n;
id outcome;
run;
(untested)
I used logic.I am getting error.
ERROR: Array subscript out of range at problemType = pt{i};
Maybe your variable names are not exactly as you say and there is a name conflict... My code assumes that the list of problemType variables matches the list of outcome variables (same number and order).
Try using unrelated variable names to avoid conflict
data test2;
set testdata;
array pt{*} problemType:;
array o{*} outcome:;
do i = 1 to dim(pt);
cat = substr(vname(pt{i}), 12);
pType = pt{i};
outcm = o{i};
output;
end;
keep No cat pType outcm;
run;
proc sql;
create table counts as
select pType, outcm, count(*) as n
from test2
group by pType, outcm;
quit;
proc transpose data=counts;
where pType = "aa";
var n;
id outcm;
run;
Great! Make sure your variables lists match. Otherwise you will be pairing outcomes with the wrong problem types.
Cheers!
Proc contents output for input data set looks like ???
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 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.
Ready to level-up your skills? Choose your own adventure.