New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chinna0369
Pyrite | Level 9

Hi all, 

 

1. How Can I Convert sas dataset into "Pipe-delimited ASCII file with a .dat extension"?

 

2. To Create CSV file I am using below code but it's giving me excel file. So How Can I Convert sas dataset into "CSV"?

proc export data=inputdataset
outfile="&PROJROOT.\Analysis\&csvFileName"
dbms=csv replace;
run;

 

Thanks,

Adi

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

but one of my drug name has DEC03 so when it comes to that CSV file it is showing it gas 3-Dec. How can I solve this?

Your CSV file is fine. The problem is that you are using Excel to look at the file.  A CSV file has no information about the the data types for a column. So the program that reads it has to set its own data types. Excel does a bad job of this.

 

Either open the file in some other application.  Or if you must open it with Excel then start Excel first and use the menus to open the file so you get a step along the way to tell it what type of data each column contains.  In my current version of Excel there is a menu option "From Text/CSV" under the "Data" menu.

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Your second example is NOT giving you an Excel file. It is creating a CSV file.  You might be allowing your computer to automatically open Excel to read the file, but it is NOT an Excel file.

 

Did you read the manual on PROC EXPORT?  Do you have specific questions about how to use it?  Did you find the section for how to set the delimiter that is used?  Show what you have tried and the resulting lines from the SAS log.  Make sure to use the Insert Code icon to get a pop-up window where you can paste the lines so the forum doesn't try to format it as if it was text paragraphs.

ballardw
Super User

One way:

proc export data=inputdataset
   outfile="&PROJROOT.\Analysis\filename.dat"
   dbms=dlm replace;
   dlm='|';
run;

Or use the Data export wizard.

 

You did not show the value of your "csvfilename" macro variable so replaced it with something without macros to have an idea what should go there.

chinna0369
Pyrite | Level 9

Yes, that works well. Thank you for that.

 

I have one more question:

 I am using below code for creating a CSV file:

proc export data=export
outfile="&PROJROOT.\Analysis\&csvFileName"
dbms=csv replace;
run;

 

but one of my drug name has DEC03 so when it comes to that CSV file it is showing it gas 3-Dec. How can I solve this?

 

Thank you in advance! 

 

 

Tom
Super User Tom
Super User

but one of my drug name has DEC03 so when it comes to that CSV file it is showing it gas 3-Dec. How can I solve this?

Your CSV file is fine. The problem is that you are using Excel to look at the file.  A CSV file has no information about the the data types for a column. So the program that reads it has to set its own data types. Excel does a bad job of this.

 

Either open the file in some other application.  Or if you must open it with Excel then start Excel first and use the menus to open the file so you get a step along the way to tell it what type of data each column contains.  In my current version of Excel there is a menu option "From Text/CSV" under the "Data" menu.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2981 views
  • 0 likes
  • 3 in conversation