[Hi everyone, in dataset in figure 1 my goal is to say, for each usubjid patient, if the avalc value reported for paramcd=WFNSECRF is equal to that reported for paramcd=WFNSIRT. For example for patient ID-054-304-1101002 these two values are the same while for patient ID-054-304-1107007 they differ. In particular I have to create the variable discrepancy in which I put 'No' if the values are equal and 'Yes' if they are different. How can I do it?
Thanks in advance for the answers] 1
This is easily done by using proc sql with a simple case statement.
data have;
input USUBJID :$20. PARAMCD :$15. AVALC :$10.;
datalines;
ID-054-304-1101001 WFNSECRF GRADE_I
ID-054-304-1101002 WFNSECRF GRADE_I
ID-054-304-1101002 WFNSIRT GRADE_I
ID-054-304-1101003 WFNSECRF GRADE_I
ID-054-304-1101004 WFNSECRF GRADE_I
ID-054-304-1101004 WFNSECRF GRADE_II
ID-054-304-1101004 WFNSIRT GRADE_II
ID-054-304-1101005 WFNSECRF GRADE_I
ID-054-304-1101005 WFNSIRT GRADE_II
ID-054-304-1101006 WFNSECRF GRADE_I
ID-054-304-1101007 WFNSIRT GRADE_I
;
run;
If every AVALC value in the same USUBJID is the same, then count(distinct avalc) will equal 1, so value of your discrepancy should be No. For every other potential case, the value will be Yes, including if AVALC value is missing altogether.
proc sql;
create table want as
select *, case
when count(distinct avalc) = 1 then 'No'
else 'Yes'
end as discrepancy
from have
group by usubjid
;
quit;