I want to create WANT dataset as mentioned below although if one of source dataset don't exist. I tried the code below but it is not working. In real life HAVE1 dataset exist for sure with some data but HAVE2 dataset will not exist all the time. HAVE1 and HAVE2 dataset will be in same structure.
So I want to dynamically write one code similar to the one mentioned below to create WANT dataset.
data have1;
id=1;
output;
run;
/*create dataset want even if have2 dataset don't exist*/
data want;
set have1 have2;
run;
log:
26 data have1;
27 id=1;
28 output;
29 run;
NOTE: Compression was disabled for data set WORK.HAVE1 because compression overhead would increase the size of the data set.
NOTE: The data set WORK.HAVE1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
30
31 /*create dataset want even if have2 dataset don't exist*/
32
33 data want;
34 set have1 have2;
ERROR: File WORK.HAVE2.DATA does not exist.
35 run;
Hi,
one more would be:
data have1;
id=1;
output;
run;
options NODSNFERR;
data want;
set have1 have2;
run;
options DSNFERR;
All the best
Bart
So can't we accomplish this task without querying the metadata?
Hi,
I think both, my and @Kurt_Bremser's, solutions are quite "without querying the metadata"-ish
All the best
Bart
Hi,
If you have common prefix you could try:
data want;
set have: ;
run;
all the best
Bart
Or if the list is "twisted", then you can do it like that:
data _null_;
call execute('data want; set ');
length set $ 41; drop set;
do until (set = " ");
i+1;
set = scan("have1 have2 ABC something.else", i);
if exist(set) then call execute(set);
end;
call execute('; run;');
stop;
run;
All the best
Bart
The simple method is this
data want;
set
have1
%if %sysfunc(exist(have2)) %then %do;
have2
%end;
;
run;
Hi,
one more would be:
data have1;
id=1;
output;
run;
options NODSNFERR;
data want;
set have1 have2;
run;
options DSNFERR;
All the best
Bart
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.