Hello
I want to merge data sets only if they exists (to prevent error).
Why this code is not working please?
May anyone show the way to solve the problem?
Data t01042021;
input Id x;
cards;
1 10
2 15
;
run;
Data t03042021;
input Id x;
cards;
3 14
2 16
;
run;
Data t07042021;
input Id x;
cards;
4 17
1 28
;
run;
%let list=t01042021+t02042021+t03042021+t04042021+t05042021+t06042021+t07042021;
%let n=7;
Data customers;
input ID ;
cards;
1
2
;
Run;
%macro ttt;
%do j=1 %to &n.;
%let YYYYMMDD=%scan(&List.,&j.,+);
%if %sysfunc(exist(t&YYYYMMDD.)) %then %do;
proc sort data=t&YYYYMMDD.;by ID;Run;
proc sort data=customers ;by ID;Run;
Data new&YYYYMMDD.;
merge t&YYYYMMDD.(in=a)customers(in=b);
by ID;
IF a and b;
Run;
%end;
%end;
%mend ttt;
%ttt;