BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

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.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 460 views
  • 0 likes
  • 3 in conversation