I'm working with questionnaire data that needs to be flagged if there is an inconsistency in the relationship between subject and informant(proxy). For each visit (101 - 104), there is a question about whether the informant is new (0,1) and what the relationship is with that informant (1 - 5). My data look a bit like this:
DATA test;
INPUT id visit newinft inftrel;
CARDS;
1 101 1 1
1 102 0 1
1 103 0 1
1 104 0 1
2 101 1 3
2 102 1 2
2 103 0 2
2 104 0 2
3 101 1 3
3 102 0 4
3 103 0 3
3 104 0 3
4 101 1 5
4 102 . .
4 103 0 5
4 104 0 5
5 101 1 2
5 102 0 2
5 103 0 2
5 104 0 2
6 101 1 1
6 102 1 3
6 103 . .
6 104 0 4
;
RUN;
If a relationship has changed, it MUST be accompanied by a new informant (newinft) flag. A visit-previous visit comparison would be easy since you would check if the relationship numbers were equal and, if not, whether there was a new informant indicator flag on the later visit. The problem is that there are missing visits, so sometimes you can't compare visit-previous visit, you have to compare visit to visit-before-previous visit. In the data above, ID 3 and ID 6 should be flagged for a manual check.
I'm trying to muddle through the logic and the programming at the same time. I've also transposed the dataset in an attempt to try arrays and the ALLCOMBI function, but that didn't go so well. Could someone help me figure out this algorithm?
Best, Lauren,
Lauren,
All of these examples assume that your data is already sorted BY ID VISIT.
If you didn't have the issue of missing visits, you could identify problem records like this:
data want;
set have;
by id inftrel notsorted;
if (first.inftrel and newinft=0) or (first.inftrel=0 and newinft=1);
run;
Luckily,modifying this to skip the missing visits is straightforward. Just add this statement to the DATA step:
where inftrel > .;
In theory, this code would fail to identify records that have INFTREL=. and NEWINFT=0 or 1. But those are fairly easy to identify separately.
Good luck.
Lauren,
All of these examples assume that your data is already sorted BY ID VISIT.
If you didn't have the issue of missing visits, you could identify problem records like this:
data want;
set have;
by id inftrel notsorted;
if (first.inftrel and newinft=0) or (first.inftrel=0 and newinft=1);
run;
Luckily,modifying this to skip the missing visits is straightforward. Just add this statement to the DATA step:
where inftrel > .;
In theory, this code would fail to identify records that have INFTREL=. and NEWINFT=0 or 1. But those are fairly easy to identify separately.
Good luck.
That worked beautifully! Thank you so much for your help!
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: