DATA Step, Macro, Functions and more

Cross Visit Consistency

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Cross Visit Consistency

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,


Accepted Solutions
Solution
‎07-11-2013 04:19 PM
Super User
Posts: 5,083

Re: Cross Visit Consistency

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.

View solution in original post


All Replies
Solution
‎07-11-2013 04:19 PM
Super User
Posts: 5,083

Re: Cross Visit Consistency

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.

Contributor
Posts: 23

Re: Cross Visit Consistency

That worked beautifully! Thank you so much for your help!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 149 views
  • 0 likes
  • 2 in conversation