Proc Export

Reply
Frequent Contributor
Posts: 116

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;
quit;

 

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

 

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

options symbolgen mprint mlogic;
%a;

 

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

 

Thanks & Regards,

Sanjay.

Super User
Super User
Posts: 7,430

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;
run;

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: 6,972

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
Ask a Question
Discussion stats
  • 2 replies
  • 89 views
  • 0 likes
  • 3 in conversation