- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-25-2017 07:38 AM
(2889 views)
Hi,
I have this macro, which I run in a loop:
%macro union( input_table, output_table, loop); %if &loop. = 1 %then %do; data &output_table.; set &input_table.; run; %end; %else %do; PROC APPEND BASE= &output_table. DATA= &input_table. force; %end; PROC DELETE DATA= &input_table.; %mend union;
It works well. But I am sure there is better practice to avoid using loop value.
Is there a way for the Proc APPEND to detect if the output_table exists, and if not to create it naturally with the input table?
Thanks
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can use proc append with a non-existing base table without problems:
data have;
x1 = 1;
run;
proc append
data=have
base=out
;
run;
Log:
24 data have; 25 x1 = 1; 26 run; NOTE: The data set WORK.HAVE has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 27 28 proc append 29 data=have 30 base=out 31 ; 32 run; NOTE: Appending WORK.HAVE to WORK.OUT. NOTE: BASE data set does not exist. DATA file is being copied to BASE file. NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: The data set WORK.OUT has 1 observations and 1 variables. NOTE: PROCEDURE APPEND used (Total process time): real time 0.01 seconds cpu time 0.00 seconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The question is, why you have so many related datasets that need appending, such that you need a macro to do this. I would suggest you look into By Group processing, which is a core SAS feature used to do operations on groups of data, as I suspect your running procedures of blocks of data individually yourself, and then setting them back together again at the end.