Hi all,
I found a macro that appends one dataset to the bottom of another and keeps the greater variable length between the 2 sets of variables:
I'm trying to adapt this macro so that the macro accepts as many input dataset names as I give it and outputs to the last dataset name given using the parmbuff option:
Here is my code thus far:
I get the following error while running %union(test1, test2, test) on existing datasets test1 and test2:
Any ideas on how to make this code work?
I found a macro that appends one dataset to the bottom of another and keeps the greater variable length between the 2 sets of variables:
I'm trying to adapt this macro so that the macro accepts as many input dataset names as I give it and outputs to the last dataset name given using the parmbuff option:
Here is my code thus far:
Code:
%macro union /parmbuff; *allows for varying number of input dataset names. The last name is always the output dataset.;
%let num = 1; *initializes name counter;
%let indsname = %scan(&syspbuff,&num); *scans the first dataset name;
%let outdsname = %scan(&syspbuff,-1); *scans the last (master/output) dataset name;
%let num=%eval(&num+1); *increments name counter from 1 to 2;
data &outdsname; set &indsname; run; *adds the first dataset to the currently empty master dataset;
%do %until (&indsname = &outdsname); *repeats loop for as many times as there are input dataset names;
proc contents data=&outdsname noprint out=out1(keep=name type length where=(type=2)); *gets lengths;
proc contents data=&indsname noprint out=out2(keep=name type length where=(type=2));
run;
data _null_; *merges current and master dataset;
file "combined.sas";
merge out1 out2(rename=(length=length2)) end=last;
by name;
if _n_ = 1 then put "Data &outdsname;";
l = max(length,length2); *gets the longer length for each variable;
put " length " name " $ " l 2. ";";
if last then do;
put " set &outdsname &indsname;";
put "run;";
end;
run;
%include "combined.sas";
%let num = %eval(&num+1); *increments name counter by 1 and rerun loop;
%let indsname = %scan(&syspbuff,&num); *scans the next dataset name;
%end;
%mend union;
I get the following error while running %union(test1, test2, test) on existing datasets test1 and test2:
Code:
ERROR: Read Access Violation In Task [ CONTENTS )
Exception occurred at (679839DF)
Task Traceback
Address Frame (DBGHELP API Version 4.0 rev 5)
679839DF 05C7E6D8 sasxkern:mcn_main+0x329DF
679036EC 05C7EDC4 sasyh:mcn_main+0x126EC
678FE367 05C7F3BC sasyh:mcn_main+0xD367
678F20E8 05C7F5DC sasyh:mcn_main+0x10E8
671B1626 05C7FB48 sasyoio:mcn_main+0x10626
671AF417 05C7FC88 sasyoio:mcn_main+0xE417
6786B59A 05C7FCC0 sasxshel:mcn_main+0x2A59A
67867E62 05C7FDB4 sasxshel:mcn_main+0x26E62
67871D03 05C7FE44 sasxshel:mcn_main+0x30D03
67871381 05C7FE54 sasxshel:mcn_main+0x30381
67872285 05C7FEB4 sasxshel:mcn_main+0x31285
670FE60F 05C7FEF0 sasqutil:mcn_main+0x3D60F
670C1449 05C7FF88 sasqutil:mcn_main+0x449
01272B02 05C7FFA0 sashost:Main+0xBE72
01276C20 05C7FFB4 sashost:Main+0xFF90
7C80B683 05C7FFEC kernel32:GetModuleFileNameA+0x1B4
Any ideas on how to make this code work?