LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 15 Sep 2010 11:27:08 -0700
Reply-To:   "Tolbert, William" <tolbert.w@GHC.ORG>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Tolbert, William" <tolbert.w@GHC.ORG>
Subject:   Re: A data step question: comparison of values of multiple variables
In-Reply-To:   <16FD64291482A34F995D2AF14A5C932C09632979@MAIL002.prod.ds.russell.com>
Content-Type:   text/plain; charset="us-ascii"

Building on Mark's sample dataset, here is a hash object approach. It may offer some efficiency when there are many variables because as soon as it finds a "hit" it leaves the loop and proceeds to the next record -- not bothering to look further.

data diffs (keep=patient_id); length patient_id 8 value 8; if _n_ eq 1 then do; declare hash ids(); ids.defineKey('patient_id','value'); ids.defineDone(); end; set sample; array var_array(9) _01-_09; rc = ids.clear(); do i = 1 to 9; if var_array(i) ne . then do; value = var_array(i); if ids.find() ne 0 then ids.add(); if ids.num_items gt 1 then do; output; leave; end; end; end; run;

Bill

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Terjeson, Mark > Sent: Wednesday, September 15, 2010 10:30 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: A data step question: comparison of values of > multiple variables > > Hi Daixin, > > Here is one approach: > > data sample; > infile cards missover; > input PATIENT_ID _01 _02 _03 > _04 _05 _06 _07 _08 _09; > cards; > 001 8310 > 002 3510 8310 > 003 7500 > 004 1010 > 005 6910 8310 > 006 . 8310 > 007 0600 > 008 2100 2100 > 009 8000 8000 8000 > 010 . 3500 > ; > run; > > proc transpose data=sample out=temp1; > by PATIENT_ID; > var _:; > run; > > proc sql; > create table diffs as > select PATIENT_ID > from temp1 > where col1 ne . > group by PATIENT_ID > having count(distinct col1) gt 1 > ; > quit; > > > > > Hope this is helpful. > > > Mark Terjeson > Investment Business Intelligence > Investment Management & Research > Russell Investments > 253-439-2367 > > > Russell > Global Leaders in Multi-Manager Investing > > > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Daixin Yin > Sent: Wednesday, September 15, 2010 10:04 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: A data step question: comparison of values of > multiple variables > > Hi there, > I have a quesion about comparing values of multiple variables > within an observation. > > Here's how my dataset looks like: > PATIENT_ID _01 _02 _03 _04 _00 _05 _07 _60 _06 _08 _09 > -------------------------------------------------------------- > --------- > 001 8310 > 002 3510 8310 > 003 7500 > 004 1010 > 005 6910 8310 > 006 8310 > 007 0600 > 008 2100 2100 > 009 8000 8000 8000 > 010 3500 > > Each observation has at least one non-missing value in > variable _00 to _60. I want to identify observations that had > unequal values in variable _00 to _60, such as PATIENT_ID 002 > and 005 in the above sample dataset. > > I believe that there must be more than one easy and efficient > way to do. > Thanks for your help!! >

GHC Confidentiality Statement

This message and any attached files might contain confidential information protected by federal and state law. The information is intended only for the use of the individual(s) or entities originally named as addressees. The improper disclosure of such information may be subject to civil or criminal penalties. If this message reached you in error, please contact the sender and destroy this message. Disclosing, copying, forwarding, or distributing the information by unauthorized individuals or entities is strictly prohibited by law.


Back to: Top of message | Previous page | Main SAS-L page