Question: I need to output lots of different datasets to different text files. The datasets share some common variables that need to be output but also have quite a lot of different ones. I have loaded these different ones into a macro variable separated by blanks so that I can macroize this.

So I created a macro which loops over the datasets and outputs each into a different text file. 

For this purpose, I used a put statement inside a data step. The PUT statement looks like this:

```
PUT (all the common variables shared by all the datasets), (macro variable containing all the dataset-specific variables);

```

E.g.:

```
%MACRO OUTPUT();
    %DO N=1 %TO &TABLES_COUNT;
        DATA _NULL_;
            SET &&TABLE&N;
            FILE 'PATH/&&TABLE&N..txt';
            PUT a b c d "&vars";
        RUN;
    %END;
%MEND OUTPUT;

```

Where &vars is the macro variable containing all the variables needed for outputting for a dataset in the current loop.
Which gets resolved, for example, to:

```
PUT a b c d special1 special2 special5 ... special329;

```

Now the problem is, the quoted string can only be 262 characters long. And some of my datasets I am trying to output have so many variables to be output that this macro variable which is a quoted string and holds all those variables will be much longer than that. Is there any other way how I can do this?

Answer: 
Do not include quotes around the list of variable names. 

```
put a b c d &vars ;

```

There should not be any limit to the number of variables you can output, but if the length of the output line gets too long SAS will wrap to a new line. The default line length is currently 32,767 (but older versions of SAS use 256 as the default line length). You can actually set that much higher if you want. So you could use 1,000,000 for example. The upper limit probably depends on your operating system.

```
FILE "PATH/&&TABLE&N..txt" lrecl=1000000 ;

```

If you just want to make sure that the common variables appear at the front (that is you are not excluding any of the variables) then perhaps you don't need the list of variables for each table at all.

```
DATA _NULL_;
  retain a b c d ;
  SET &&TABLE&N;
  FILE "&PATH/&&TABLE&N..txt" lrecl=1000000;
  put (_all_) (+0) ;
RUN;

```
I would tackle this but having 1 put statement per variable. Use the `@` modifier so that you don't get a new line.

For example:

```
data test;
a=1;
b=2;
c=3;
output;
output;
run;

data _null_;
set test;
put a @;
put b @;
put c @;
put;
run;

```

Outputs this to the log:

> 
> 
> ```
> 800  data _null_;
> 801  set test;
> 802  put a @;
> 803  put b @;
> 804  put c @;
> 805  put;
> 806  run;
> 
> 1 2 3
> 1 2 3
> NOTE: There were 2 observations read from the data set WORK.TEST.
> NOTE: DATA statement used (Total process time):
>       real time           0.07 seconds
>       cpu time            0.03 seconds
> 
> ```
> 
> 

So modify your macro to loop through the two sets of values using this syntax.