|
On 11 Jun, 15:17, thomas <adds...@googlemail.com> wrote:
> Hi,
> I'm still a beginner in macro programming, and need a tip how to
> program the following data steps using a macro and array definition
> within the macro.
>
> A data-set bigfile consists of 2x12 variables a01-a2, b01-12.
> For an external program, I need 12 files "smallfile_i" with 2 columns
> ai, bi (smallfile_1: a1, b1; smallfile_2 : a2, b2; ...).
>
> Of course I could use 12 times a datastep with increasing i, starting
> with:
>
> data smallfile_1 (keep=aa bb);
> set bigfile;
> aa=a01;
> bb=b01;
> run;
> .....
>
> but I would like to get a solution within a macro (or within 1
> procedure).
> My idea was
>
> %macro manyfiles;
> %do i=1 %to 12;
> data smallfile_&i (keep=aa bb);
> set bigfile;
> array test1 {12} a01-a12;
> array test2 {12} b01-b12;
> aa=test1{i};
> bb=test2{i};
> run;
> %end;
> %mend;
> %manyfiles;
>
> However it does not work because of problems with the arrays.
>
> (The macro works, if I do not use array-definition, and
> aa=a01;
> bb=b01;
> [--> all smallfiles are identical just to test the steps])
>
> Thank you for any hint!
Thomas,
I'm a little confused about your requirements so this may not be
precisely what you want,
However, if you simply want to break out 12 datasets from the one then
the following code should help:
/* create the big file (for testing) with 12 pairs of datasets. */
data
bf;
a01=1; a02=2; a03=3; a04=4; a05=5; a06=6; a07=7; a08=8; a09=9;
a10=10; a11=11; a12=12;
b01=1; b02=2; b03=3; b04=4; b05=5; b06=6; b07=7; b08=8; b09=9;
b10=10; b11=11; b12=12;
run;
/* set up a macro to generate the output datasets and their paired
variables */
%MACRO
multiout(outputs);
DATA
%do i = 1 %to
&outputs;
sf&i(keep=a%SYSFUNC(putn(&i,z2. -
l))
b%SYSFUNC(putn(&i,z2. -
l)))
%END; ;
set
bf;
RUN;
%MEND
multiout;
options
macrogen;
/* Run the macro with a request for 12 datasets and 12 paired
variables */
%multiout(12)
The ouput form this program is:
MACROGEN(MULTIOUT): DATA sf1(keep=a01 b01) sf2(keep=a02 b02)
sf3(keep=a03 b03) sf4(keep=a04 b04)
sf5(keep=a05 b05) sf6(keep=a06 b06) sf7(keep=a07 b07) sf8(keep=a08
b08) sf9(keep=a09 b09)
sf10(keep=a10 b10) sf11(keep=a11 b11) sf12(keep=a12 b12) ;
MACROGEN(MULTIOUT): set bf;
MACROGEN(MULTIOUT): RUN;
NOTE: There were 1 observations read from the data set WORK.BF.
NOTE: The data set WORK.SF1 has 1 observations and 2 variables.
NOTE: The data set WORK.SF2 has 1 observations and 2 variables.
NOTE: The data set WORK.SF3 has 1 observations and 2 variables.
NOTE: The data set WORK.SF4 has 1 observations and 2 variables.
NOTE: The data set WORK.SF5 has 1 observations and 2 variables.
NOTE: The data set WORK.SF6 has 1 observations and 2 variables.
NOTE: The data set WORK.SF7 has 1 observations and 2 variables.
NOTE: The data set WORK.SF8 has 1 observations and 2 variables.
NOTE: The data set WORK.SF9 has 1 observations and 2 variables.
NOTE: The data set WORK.SF10 has 1 observations and 2 variables.
NOTE: The data set WORK.SF11 has 1 observations and 2 variables.
NOTE: The data set WORK.SF12 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.06 seconds
If this isn't quite what you want then perhaps you could give more
detail of expected inputs and outputs.
Good luck with it.
Regards,
Barry D.
|