|
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.
>
|