```Date: Tue, 7 Apr 2009 10:10:42 -0500 Reply-To: "./ ADD NAME=Data _null_;" Sender: "SAS(r) Discussion" From: "./ ADD NAME=Data _null_;" Subject: Re: Compare a number of variables to one another for equivalence- function? Comments: To: Joe Matise In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 I though the question was, "Are any of the pairwise differences zero?". PROC COMPARE is good at differences or you could use PROC SCORE to compute the differences. If you wanted to actually compute all the differences which is unnecessary. The methods that stop looking as soon as the criterion is meet are clearly better. proc plan seed=1895529354; factors id = 10 ordered v1=1 of 5 v2=1 of 5 v3 = 1 of 5 v4 = 1 of 5 v5 = 1 of 5 / noprint; output out=test; run; proc print; run; *** Pairwise scoring coefficients; %let vars=v1-v5; data score; retain _type_ 'SCORE'; length _name_ \$8; array v[*] &vars; do i = 1 to dim(v); do j = i+1 to dim(v); _name_ = cats('D',i,j); do k = 1 to dim(v); if k eq i then v[k]=1; else if k eq j then v[k]=-1; else v[k]=0; end; output; end; end; drop i j k; run; proc print; run; proc score data=test score=score out=dif; var v1-v5; run; proc print; run; *** Pairwise VAR/WITH statements; proc compare data=test out=comp outdif noprint; id id; var v2 v3 v4 v5; with v1 v1 v1 v1; var v3 v4 v5; with v2 v2 v2; var v4 v5; with v3 v3; var v5; with v4; run; proc print data=comp; run; On 4/7/09, Joe Matise wrote: > Along those lines, if they're numeric, you could also use the VAR function > (variance): > > data test; > input a b c d e; > datalines; > 1 1 1 1 1 > 1 2 1 1 1 > 2 2 2 2 2 > 2 2 2 3 2 > 2 3 2 2 2 > 4 4 4 4 4 > ; > run; > > data test; > set test; > equiv = ^var(of a--e); > run; > > -Joe > > On Tue, Apr 7, 2009 at 9:39 AM, Mike Zdeb wrote: > > > hi ... I interpret the question as > > > > does each variable within a given set of variables in an observation all > > have the same value > > > > if that's the task, then I think this works OK ... > > (if it's not the task, it still works OK, it just doesn't answerr your > > question) > > > > > > data test; > > input a b c d e; > > datalines; > > 1 1 1 1 1 > > 1 2 1 1 1 > > 2 2 2 2 2 > > 2 2 2 3 2 > > 2 3 2 2 2 > > 4 4 4 4 4 > > ; > > run; > > > > data test; > > set test; > > equiv = (cats(of a--e) eq repeat(cats(a),4)); > > run; > > > > proc print data=test; > > run; > > > > -- > > Mike Zdeb > > U@Albany School of Public Health > > One University Place > > Rensselaer, New York 12144-3456 > > P/518-402-6479 F/630-604-1475 > > > > > On Apr 7, 9:43 am, countitd...@gmail.com wrote: > > >> Hi, > > >> > > >> I was wondering if there is a function is SAS that allows one to > > >> compare a number of variables to one another to check for > > >> equivalence. > > >> > > >> For instance, I have 5 variables that I would like to check. > > >> As opposed to checking var1 to var2, var1 to var3, var2 to var3, etc, > > >> is there a function similar to NMISS compare these in one step? > > >> > > >> Thanks! > > > > > > Additionally, I only want to know if any are equivalent, ie return 1 > > > if yes, 0 if no. I don't need to know which ones are, arent. > > > > > > > > > ```

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