05-03-2017 04:10 AM
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
select count (distinct name) into : c
select distinct name into:name1-:name%sysfunc(compress(&c)) from
%do i=1 %to &c;
proc export data=ab_&&name&i. outfile="path\ab_&&name&i...csv" dbms=csv replace;
options symbolgen mprint mlogic;
Note: In my scnerio name have more then 32 charecters.
Thanks & Regards,
05-03-2017 04:19 AM - edited 05-03-2017 04:20 AM
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.
05-03-2017 04:27 AM
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.