Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a recursive reference to &amp;numvars, which is a problem in and of itself, but not a critical one - just means that the default value will be null, not the value you intend it to be. Otherwise your code works fine for me. I would guess you have something else going wrong just before the %macro definition; the error you post makes it look like you have a token that's incorrectly resolving, so instead of %macro export(</p> <p>you have %macro (</p> <p>Anyway, this is what works for me:</p> <pre><code>%let g=c:\temp; libname g "&amp;g."; %macro export(libname, numvars=); %do i= 1 %to &amp;numvars.; proc export data=sashelp.class DBMS=CSV REPLACE outfile= "&amp;g.\StateZip&amp;i.csv"; run; %end; %mend; %export(&amp;g, numvars= 51); </code></pre> <p>The things I changed: * You need a %let g= to go along with your libname. You don't have that defined, but presumably you do elsewhere. * Sashelp.class instead of using your library as I don't have those datasets.</p> <p>The better answer, though, is probably to do it like this, using FILEVAR option and writing them out yourself. Even if you have a ton of variables, you can either programmatically determine the put statement, or just do one proc export and copy from the log. This avoids all of the macro stuff, and avoids you having to make 51 different datasets. Just make one, with an indicator variable. Pretty much no matter what you're doing, this will be faster (using BY group processing with PROCs, etc.) and less error-prone than having a bunch of different datasets and making up for it with macros.</p> <pre><code>data have_51; set sashelp.class; do _n = 1 to 51; output; end; run; *I assume you have have_51 already; data want; set have_51; filename=cats("&amp;g.\StateZip",_n,".csv"); run; proc sort data=want; by filename; run; data _null_; set want; file a filevar=filename dlm=',' lrecl=500; put name $ age height weight ; run; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload