DATA Step, Macro, Functions and more

exporting a CSV

Reply
Contributor
Posts: 47

exporting a CSV

Hello

I have a dataset called new which have three columns

 

name age salary

 

when I am exporting this dataset into CSV through proc export

 

proc export data=new dbms=csv
outfile="L\new\sample.csv" replace;
run;

 

when I am opening the CSV file it shows all the three columns in one column in CSV

 

name,age,salary
rohit,12,20000
sagar,15,50000

 

But what i want all the three columns in three columns in CSV not in one column

 

How can I acheive that

PROC Star
Posts: 1,218

Re: exporting a CSV

You do have three "columns" here, separated by commas, which is what a CSV file is.

 

I take it you open this file in some Spreadsheet program like Microsoft Excel and want it to appear in three columns instead of 1?

 

You can do this either in Excel itself or by simply exporting the file as an .xlsx file to begin with.

 

Do a Google search, millions of examples there...

Super User
Super User
Posts: 9,441

Re: exporting a CSV

What is it you actually want?   CSV = Comma Separated Variable file.  This is one optional row with headers, each separated by commas, then one row per data line with data separated by commas.   Which is exactly what you have there.

"when I am opening the CSV file" - and how and with what are you opening the file?  If its association is with a text program like notepad then you will see it as plain text, if you associate it with Excel then Excel will open and parse it into a grid - this does not change the underlying structure or anything unless you save it.

Contributor
Posts: 36

Re: exporting a CSV

working perfectly fine

data CSV_TEST;
input name $ age salary;
datalines;
rohit 12 20000
sagar 15 50000
run;

proc export data=Work.csv_test dbms=csv
outfile=".....\sample.csv" replace; /*Add your Path*/
run;
Frequent Contributor
Posts: 79

Re: exporting a CSV

Your CSV file is created perfectly. It's just you have to use the MS Excel or any other spreasheet program to open it to show in 3 columns.

A text editor like notepad wordpad etc will show it in one line only, like you mentioned.

Cheers from India!

Manjeet
Contributor
Posts: 36

Re: exporting a CSV

I just opened this file with notepad++ and it is perfectly in three line and comma separated as below

 

name,age,salary
rohit,12,20000
sagar,15,50000

Super User
Posts: 23,342

Re: exporting a CSV

CSV -> comma separated values. 

Your file has comma separated values.

 

CSV files have no concept of 'columns'. 

 

If you open the file in Excel, unfortunately, the default, it will show as three separate 'columns'. In this example it will work fine, but Excel can also misinterpret your data so be careful working that way.

 

 

Ask a Question
Discussion stats
  • 6 replies
  • 118 views
  • 7 likes
  • 6 in conversation