BookmarkSubscribeRSS Feed
kmardinian
Quartz | Level 8

Hi, I am trying to export a csv file from a SAS dataset I created, but I am trying to figure out a way to get rid of the last comma that shows up when I view the csv file in notepad. Is there a way of doing this? Any help is greatly appreciated! Thank you!


This is the code I am using to export my dataset.

 

proc export data=dt
   outfile="&Outpath.&outfile..csv"
   dbms=csv replace;
   delimiter='|';
 run;

5 REPLIES 5
Reeza
Super User

You've specified the delimiter as a pipe, that isn't a csv file. I would recommend the following changes:

1. Change it to a txt file, since it's a pipe delimited text file

2. Change DMBS to DLM (delimited) rather than CSV

 

proc export data=dt
   outfile="&Outpath.&outfile..txt"
   dbms=DLM replace;
   delimiter='|';
 run;

@kmardinian wrote:

Hi, I am trying to export a csv file from a SAS dataset I created, but I am trying to figure out a way to get rid of the last comma that shows up when I view the csv file in notepad. Is there a way of doing this? Any help is greatly appreciated! Thank you!


This is the code I am using to export my dataset.

 

proc export data=dt
   outfile="&Outpath.&outfile..csv"
   dbms=csv replace;
   delimiter='|';
 run;


 

kmardinian
Quartz | Level 8

I see, do you know if that would be the only way to do this. There isn't a possibility of fixing this issue, but also keeping it as a csv file? A csv file is what I wanted the output to be in.

Kurt_Bremser
Super User

csv means comma separated volume, so it does not use pipes as delimiter, but commas.

Anyway, anytime the last column in the SAS dataset is empty, the corresponding line in the output will end with a delimiter, per definition.

Reeza
Super User

You can name it whatever you want, but it's not a CSV file. The reason to not do this is to avoid confusion from end users. 

You can leave the extension as CSV and make the other changes (DBMS).


@kmardinian wrote:

I see, do you know if that would be the only way to do this. There isn't a possibility of fixing this issue, but also keeping it as a csv file? A csv file is what I wanted the output to be in.


 

ballardw
Super User

Change

proc export data=dt

to

 

proc export data=dt(drop=lastvar)

replace lastvar with the last variable in the data set. You get the "extra" comma or pipe because you have a variable that is all missing values.

OR much less likely the values of your last variable end with a comma. At which point you need to modify your data set. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 2377 views
  • 0 likes
  • 4 in conversation