BookmarkSubscribeRSS Feed
Rohit12
Obsidian | Level 7

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

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

emrancaan
Obsidian | Level 7

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;
mnjtrana
Pyrite | Level 9
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
emrancaan
Obsidian | Level 7

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

Reeza
Super User

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 5037 views
  • 7 likes
  • 6 in conversation