BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shu1225
Fluorite | Level 6

Hi,

 

I am trying to export a very large dataset from SAS to CSV using "|" as my delimiter. I'm using the code as follows:

 

filename output "filepath" encoding="UTF-8";
 
proc export data = dataset
outfile = output
dbms = csv replace;
delimiter="|";
run;
 
However, some of the fields in the dataset contain commas and they are still being read as delimiters in the CSV files, causing columns to be broken up. Is there another way the delimiter needs to be coded to make sure commas are not read as delimiters?
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@shu1225 wrote:

I am verifying the contents of the CSV file in Excel.


Do not use Excel to check the contents of a TEXT file.  Use a TEXT Editor instead, like Notepad.

 

How did you tell Excel to open the file?  If you let Excel open a file with a .CSV extension by default it will assume the delimiter is a comma.  Instead first open Excel and then use the file import tool to read the file.  They keep moving that around in the menu's but in my current version of Excel it is under Data -> Get Data -> From File -> From Text/CSV

 

Tom_0-1719938199551.png

 

Which should then let you pick a file and pop-up with a screen where YOU can TELL Excel what delimiter to use.

Tom_1-1719938334248.png

 

 

View solution in original post

7 REPLIES 7
SASJedi
SAS Super FREQ

I'm not understanding the issue. Here is sample code:

data test;
	infile datalines dsd dlm='|';
	input Text1:$30. Text2:$30. Num1:32.; 
datalines;
Now is the time|for all good men|1
Now, it's the time|for all, good men|2
A,B,C,D|E,F,G,H|3
;

filename output "test.dlm" encoding="UTF-8";

proc export data = test
	outfile = output
	dbms = csv replace;
	delimiter="|";
run;

Which produces this result:

Text1|Text2|Num1
Now is the time|for all good men|1
Now, it's the time|for all, good men|2
A,B,C,D|E,F,G,H|3

Which is what I would expect. What were you expecting instead?

 

Check out my Jedi SAS Tricks for SAS Users
shu1225
Fluorite | Level 6

That is also what I would have expected. However, what I'm getting is this:

Text1|Text2|Num1
Now is the time|for all good men|1
Now| it's the time|for all| good men|2
A|B|C|D|E|F|G|H|3

All commas are still being read as delimiters.

SASJedi
SAS Super FREQ

I just ran this and got the results I showed you. Can you please run the test program above in a fresh SAS session and then share the complete log? 

Check out my Jedi SAS Tricks for SAS Users
Reeza
Super User
You say 'being read' are you reimporting the file somehow? How are you verifying the file contents?
shu1225
Fluorite | Level 6

I am verifying the contents of the CSV file in Excel.

Tom
Super User Tom
Super User

@shu1225 wrote:

I am verifying the contents of the CSV file in Excel.


Do not use Excel to check the contents of a TEXT file.  Use a TEXT Editor instead, like Notepad.

 

How did you tell Excel to open the file?  If you let Excel open a file with a .CSV extension by default it will assume the delimiter is a comma.  Instead first open Excel and then use the file import tool to read the file.  They keep moving that around in the menu's but in my current version of Excel it is under Data -> Get Data -> From File -> From Text/CSV

 

Tom_0-1719938199551.png

 

Which should then let you pick a file and pop-up with a screen where YOU can TELL Excel what delimiter to use.

Tom_1-1719938334248.png

 

 

shu1225
Fluorite | Level 6

I did not have Notepad on the laptop I was using. I had input it the way you mentioned for Excel but forgot to check that I needed a custom delimiter. Thanks for the help!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 924 views
  • 6 likes
  • 4 in conversation