Hello everyone,
I would like to export to the CSV format a SAS dataset with a large number of columns (~2200) with a total length of around 42000 characters when all column titles concatened. The output final CSV file doesn't exceed 400MB because of a low number of rows.
But when I open my CSV file, I see that more than 300 column names are missing. How is that possible ? Would you know how to fix it please?
More details :
-I've used a proc export to export as CSV.
-When I use a proc export to output a XLSX file, I don't get this problem.
-It seems that the problem is the total length of the concatened column names since it works well for the other rows which are shorter (when all concatened).
-It is like I need to set a LRECL option to a higher limit, but it doesn't exist in a proc export.
Thank you very much in advance for your help.
Best regards
I do a simple export as following :
proc export data=My_Table dbms=csv outfile="&month_My_Table.csv" replace; run;
&month is a number like 201501.
I've noticed the error thanks Microsoft Excel 2016 but also in another programming language.
The code created by proc export tries to write the header as one string, which exceeds the maximum length of character values (32767).
Locate the header in the code, and split it to two separate put statements with a line hold (@) in the first.
*Create demo data;
data class;
set sashelp.class;
label age='Age, Years' weight = 'Weight(lbs)' height='Height, inches';
run;
proc sql noprint;
create table temp as
select name as _name_, label as _label_
from dictionary.columns
where libname="WORK" and upcase(memname)="CLASS";
select cats(quote(name),"n") into :varList separated by ' '
from dictionary.columns
where libname="WORK" and upcase(memname)="CLASS";
quit;
data _null_;
file "&sasforum.\datasets\TwoLinesHeader.csv" dsd lrecl = 40000;
set class;
if _n_ = 1 then do;
do until(eof);
set temp end=eof;
put _name_ @;
end;
put;
put (&varList) (:);
run;
Modified version of this which prints names and labels. I removed the labels section.
https://gist.github.com/statgeek/ae153e40af0d35dce02d1c8102ff3b94
Thanks for your answer. However it could work but I got several errors when trying it, the first one being :
proc sql noprint;
select cats(quote(name),"n")into : varList separated by ' ' from dictionary.columns where LIBNAME = upcase("WORK") and MEMNAME = upcase("My_Table"); quit; %put &varList.;
But on the other hand, it works when removing the CATS and QUOTE functions such as :
proc sql noprint; select name into : varList separated by ' ' from dictionary.columns where LIBNAME = upcase("WORK") and MEMNAME = upcase("My_Table"); quit; %put &varList.;
Would you know how to "overpass" this limit please ?
If you work with
options validvarname=v7;
set, you don't need the CATS() and QUOTE() functions, because you can't have blanks in variable names.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.