@jessho wrote:
Awesome -- thank you.
When I run the code above, I get this output:
diagnosis_code1 diagnosis_code2 diagnosis_code3 diagnosis_code4 diagnosis_code5 diagnosis_code6 diagnosis_code7 PSTD F43.10 F43.12 F43.13 F43.9 F43.0 F43.8 1
However, I cannot seem to count the number of times the diagnosis of PTSD was made during each visit (PTSD response for variable diagnosis_code1, diagnosis_code2, etc) for each patient in the dataset from this. Proc freq does not recognize PTSD? How would I do that?
Also, just to get clarity on exactly what $icd_pst pulls up so that I understand the logic, could you explain further?
Thank you!
If you are using this code, it only sets the value to 1, so no "count"
data test;
set WORK.testunder1;
array diags {8} diagnosis_code_1 - diagnosis_code_8;
do k = 1 to 8 until (ptsd=1);
If Put(diags{k}, icd_pst.) = 'PTSD' then PTSD=1;
end;run;
Likely not the best but
data test;
set WORK.testunder1;
array diags {8} diagnosis_code_1 - diagnosis_code_8;
do k = 1 to 8 until (ptsd=1);
Ptsd= sum(ptsd,Put(diags{k}, icd_pst.) = 'PTSD');
end;run;
Personally I would transpose the data to a long format with a diagnosis id and separate value and use a single format to count all the diagnosis code groups at one time similar to:
proc format library=work;
value $example
'A','B'='Group1'
'C','D','E' = 'Group 2'
other = 'Everything else'
;
run;
data example;
input pid vid did dv $;
label pid='Patient'
vid='Visit number'
dv= 'Diagnosis group'
;
datalines;
1 1 1 A
1 1 2 B
1 1 3 F
1 2 1 F
1 2 2 F
1 2 3 C
1 2 4 B
2 1 1 A
2 1 2 B
2 2 3 F
2 2 1 F
2 3 2 F
2 3 3 C
2 3 4 B
;
run;
proc tabulate data=example;
class pid vid dv;
format dv $example.;
table pid*vid*dv,
n='Count'
;
run;
... View more