Community talk about communities.sas.com. Meta!

How to attribute a value of a given variable of a case to its matched control

Reply
Occasional Contributor
Posts: 7

How to attribute a value of a given variable of a case to its matched control


 Hi dear,

 

I will be grateful if someone can help me with the following query: 

I have cases matched to controls and I need to attribute a value of a case for a given variable to the corresponding matched control. as detailed in the tables below, I need to attribute the value "1" of the "Varx' of the case to the control (case=0) so that the value of the control for varx become 1 instead of missing. 

 

Input table;

ID   Macth_ID  case   Varx

1     1a              1        1

2     1a              0        .

 

Output expected: 

ID   Macth_ID  case   Varx

1     1a              1        1

2     1a              0        1

 

Thanks in advance for your support.

Super User
Posts: 11,810

Re: How to attribute a value of a given variable of a case to its matched control

Are you implying that your are matching on the Match_ID variable? If so, do you ever have more than two records with the same Match_id? Do you only have one non-missing value for Varx per Match_id?

Occasional Contributor
Posts: 7

Re: How to attribute a value of a given variable of a case to its matched control

Hi Ballardw

 

thanks for replying.

 

The data are already matched using the match_ID variable that identifies matched case and controls. Each case can have more than one control. Varx (that takes value 0 or 1) is missing for all the controls in the dataset but for each matched control the value of Varx is the same as for the case (i.e., if Varx =0 for the case, it should also be 0 for the matched controls). 

Hope this clarify.

 

thanks again

Super User
Posts: 20,731

Re: How to attribute a value of a given variable of a case to its matched control

This is a lookup or merge. 

 

You can use a data step merge or SQL, and the COALESCE() function is helpful.

 

Examples and explanations can be found here:

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=n1tgk0uanvisvon1r26lc036k0w7.htm&docsetVer...

Occasional Contributor
Posts: 7

Re: How to attribute a value of a given variable of a case to its matched control

Thank you reeza for your suggestion and the link you shared. It was helpful.

Have a nice weekend!

 

Highlighted
Community Manager
Posts: 605

Re: How to attribute a value of a given variable of a case to its matched control

Hi arzon,

 

I'm glad you found some useful info! If one of the replies was the exact solution to your problem, can you "Accept it as a solution"? Or if one was particularly helpful, feel free to "Like" it. This will help other community members who may run into the same issue know what worked.

Thanks!
Anna

Ask a Question
Discussion stats
  • 5 replies
  • 289 views
  • 1 like
  • 4 in conversation