BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

SAS Studio 3.8

SAS 9.4M6

 

PROC EXPORT - data has no embedded delimiters. 

 

delete1 - export CSV.png

 

PROC EXPORT, with embedded delimiters (demo2.csv)

 

delete2 - export CSV.png

Reeza
Super User

Different versions may have different specifications, that being said, what you're describing is not the default SAS behaviour many of us would expect so something else is the issue. 

 

What happens if you run the exact same code I did, replacing the path to something that makes sense for you?

 

proc export data=sashelp.class outfile='/home/fkhurshed/demo.csv' 
dbms=csv 
replace; 
run;

data class;
set sashelp.class;

if name in ('Alfred', 'Jane') then name = 'My, Name';
run;


proc export data=class outfile='/home/fkhurshed/demo2.csv' 
dbms=csv 
replace; 
run;

*check versions;
proc product_status;run;
chimukah
Obsidian | Level 7
Let me demonstrate a little :
data b1;
do sample = 1 to 15;
do unit = 1 to 3;
if unit = 1 then seq = "A";
else if unit = 2 then seq = "B";
else if unit = 3 then seq = "C";
output;
end;
end;
run;

proc export data = b1 outfile = "C:\Users\Documents\My SAS Files\9.4/My_Programmes\ran.csv" dbms=dlm label replace;
delimiter = ';'; run;



Tom
Super User Tom
Super User

Remove the LABEL option from PROC EXPORT.

If you want the column headers in the text file to use different values than the names of the variable then rename the variables.

chimukah
Obsidian | Level 7

Thank you Tom for your advice. It did the magic. However it solved the main problem which is the double quotes and also created another one which we avoided using the Label. (Main-Land)  coded as Main_Land

 

Renaming the variables (perhaps in the notepad or Excel) after Proc Export could be done outside programming environment. However, to accomplish the task accordingly, everything has to be within the programming environment.

 

Is there anyway to avoid this problem. i mean an alternative to make the variable appear in form of Main-Land instead of Main_Land

 

Thank you once again.

Tom
Super User Tom
Super User

If you set VALIDVARNAME option to ANY then those labels could be variable names. Note you are still limited to 32 bytes for the variable name. Example:

options validvarname=any;
proc export data=sashelp.class(obs=3 rename=(name='Main-Land'n)) 
  dbms=csv file=csv replace
;
  delimiter=';' ;
run;

It is not that hard to write a CSV file without using PROC EXPORT.  A simple data step will do it.  You can add a second step to first write the header row.

proc transpose data=HAVE(obs=0) out=names;
  var _all_;
run;
data _null_;
   file 'myfile.csv' dsd dlm=';' ;
   length _label_ $256 _name_ $32;
   set names ;
   _label_=coalescec(_label_,_name_);
   put _label_ @@;
run;
data _null_;
    file 'myfile.csv' dsd dlm=';' mod ;
   set have;
   put (_all_) (+0);
run;

 

chimukah
Obsidian | Level 7
A big thank you. This also solved the second problem. Both problems are solved.
chimukah
Obsidian | Level 7
data b1;
        do sample = 1 to 15;
            do  unit = 1 to 3;
               if unit = 1 then seq = "A";
               else if unit = 2 then seq = "B";
               else if unit = 3 then seq = "C";
            output;
        end;
  end;
run;

 

proc export data = b1 outfile = "C:\Users\Documents\My SAS Files\9.4\
My_Programmes\ran.csv" dbms=dlm label replace; delimiter = ';'; run;

anotations.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 24 replies
  • 9927 views
  • 12 likes
  • 6 in conversation