03-14-2017 09:28 PM - edited 03-14-2017 09:29 PM
Your code would not work. I think you want all the observations in HAVE1 with a value for VAR that also occurs in HAVE2:
if _n_=1 then do;
declare hash h (dataset:'have2 (keep=var)');
Or if you don't want implement hash objects, you can use a couple of proc sorts, followed by a merge:
proc sort data=have2 (keep=var) out=need2 nodupkey;
proc sort data=have1;
merge have1 have2 (in=in2);
The latter requires for more input/output.
03-14-2017 09:37 PM - edited 03-14-2017 09:37 PM
The data step looks more complicated.
I think a full proc sql is the simplest and readable.
proc sql; create table want as select * from have1 where var in (select distinct var in have2); quit;
03-14-2017 11:22 PM
@afiqcjohari, yes, SQL is simpler in this case, but you need the proper syntax:
proc sql; create table want as select * from have1 where var in (select var from have2); quit;
03-15-2017 04:38 AM
Agree with other that stick to SQL for the whole query is the preferred technique.
But if there's another situation, and really would benefit from nesting SQL code, take a look at DS2.