BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bailunrui
Fluorite | Level 6

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

2 REPLIES 2
Astounding
PROC Star

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.

bailunrui
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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