Proc Export

Frequent Contributor
Posts: 117

Proc Export

Hi SAS Experts,


I have to export the datasets  with more than 32 charecters. Actually i am creating a series of macro variables for my dataset and am exporting them with the same macro loop. There are many distinct values in my dataset whic i am exporting and theire length is more than 32 charecters.. Is there is any way to handle this situation.


below is a example code

proc sql;
select count (distinct name) into : c
from sashelp.class;


proc sql;
select distinct name into:name1-:name%sysfunc(compress(&c)) from


%macro a;
%do i=1 %to &c;
data ab_&&name&i.;
set sashelp.class;
where name="&&name&i."
proc export data=ab_&&name&i. outfile="path\ab_&&name&i...csv" dbms=csv replace;
%mend a;

options symbolgen mprint mlogic;


Note: In my scnerio name have more then 32 charecters.


Thanks & Regards,


Super User
Super User
Posts: 9,605

Re: Proc Export

[ Edited ]

Please follow the guidance for posting good questions.  Steep 1 post test data in the form of a datastep.  Then post what the output should look like or describe it.  It is very hard to answer anythiing clearerly without knowing what you are working with.  Why is it for instance your trying to create a dataset name with data for instance, that is never a good idea.  Here is an example using sashelp.class dataset:

proc sort data=sashelp.class out=loop nodupkey;
  by sex;

data _null_;
set loop; call execute(cats('proc export data=sashelp.class outfile="c:\workbook_for_',sex,'.csv"
replace dbms=csv; where sex="',sex,'"; run;)); run;

What this will do is create a distinct list of sex values, then for each of those values create a proc export of the data, with the name of teh sex parameter, filtered for only that data which is the sex value.  

Super User
Posts: 10,283

Re: Proc Export

Using data for filenames always carries the risk of exceeding maximum lengths for names. In the case of files, once the complete filename (including the path) exceeds ~255 (depending on OS) characters, you'll run into a problem with the operating system.


In your example, I would skip the data step that creates the sub-dataset (which might be impossible because dataset names must not exceed 32 characters), and instead use a where= dataset option in the export step. This will work until the output filename cracks the OS limit.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation