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 (February 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 28 Feb 2006 00:01:33 -0500
Reply-To:   Shawn Edney <shawnedney@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Shawn Edney <shawnedney@GMAIL.COM>
Subject:   Re: Check values in different columns
In-Reply-To:   <1141035192.941177.171200@t39g2000cwt.googlegroups.com>
Content-Type:   text/plain; charset=ISO-8859-1

To me, this task seems to beg for a datastep hash solution. Maybe like the following.

*

data* *_null_*;

if _n_=*1* then do;

declare hash h(dataset:'work.data1');

h.definekey('var1');

h.definedata('var1');

h.definedone();

end;

array v{*} var2-var4;

array c{*3*} _temporary_ (*0* *0* *0*);

set work.data2 end=last;

do inc_v=lbound(v) to hbound(v);

var1=v{inc_v};

if not(h.check()) then c{inc_v}+*1*;

end;

if last then do;

do inc_v=lbound(v) to hbound(v);

str=vname(v{inc_v})||' contains '||strip(put(c{inc_v},*8.*))||' values of var1';

put str;

end;

end; *

run*;

Returns:

var2 contains 2 values of var1

var3 contains 0 values of var1

var4 contains 3 values of var1 --Shawn

On 2/27/06, p.stat@tiscali.it <p.stat@tiscali.it> wrote: > > Hi, > > The data set data1 has 6 observations and 1 variable. > The data set data2 has 50 observations and 3 variables. > > I want to check how many observations in data1 are present also in > columns of data2. > > Example > Data1 > var1 > 1 > 2 > 3 > 4 > 5 > 6 > > data2 > var2 > 1 > 2 > 8 > 9 > 33 > ... > > var3 > 0 > 7 > 16 > 78 > 301 > ... > > var4 > 3 > 5 > 6 > 66 > 134 > ... > > Result of the data step that I'm trying to get: > > var2 contains 2 values of var1 > var3 contains 0 values of var1 > var4 contains 3 values of var1 > > > Many thanks > p. >


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