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;

```
Not sure why you're talking about quoted strings: you would not quote the &vars argument. 

```
put a b c d &vars;

```

not 

```
put a b c d "&vars";

```

There's a limit there, but it's much higher (64k).

That said, I would do this in a data driven fashion with `CALL EXECUTE`. This is pretty simple and does it all in one step, assuming you can easily determine which datasets to output from the dictionary tables in a WHERE statement. This has a limitation of 32kiB total, though if you're actually going to go over that you can work around it very easily (you can separate out various bits into multiple calls, and even structure the call so that if the callstr hits 32000 long you issue a call execute with it and then continue).

This avoids having to manage a bunch of large macro variables (your `&VAR` will really be `&&VAR&N` and will be many large macro variables).

```
data test;
  length vars callstr $32767;
  do _n_ = 1 by 1 until (last.memname);
    set sashelp.vcolumn;
    where memname in ('CLASS','CARS');
    by libname memname;
    vars = catx(' ',vars,name);
  end;
  callstr = catx(' ',
    'data _null_;',
    'set',cats(libname,'.',memname),';',
    'file',cats('"c:\temp\',memname,'.txt"'),';',
    'put',vars,';',
    'run;');
    call execute(callstr);
run;

```