DATA Step, Macro, Functions and more

Proc Export to CSV issue - need to change csv tab name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Proc Export to CSV issue - need to change csv tab name

I have a scipt - that runs great, it does a proc export to a .csv file file. It's dynamic (see https://communities.sas.com/t5/Base-SAS-Programming/SAS-Automation-Export/td-p/315194) for the full script... My issue is that while it run great, the CSV ouput that is created also creates the data with a tab name that is the same as the outout file name.. So if my output is core_fed_ack_gen_data_12_06_182127.csv then the tab name inside the csv is core_fed_ack_gen_data_12_06_182 (it cuts off a few chars - but no biggie).. What I would like to do is find a way to genericize just the tab name to core_fed_ack_gen_data or even just sheet 1 or whatever... 

 

Thanks in advance

 

proc export

data=ALL

outfile="C:\Users\d7dmb\Documents\core_fed_ack_gen_data_12_06_182127.csv"

dbms=csv

replace


Accepted Solutions
Solution
‎01-06-2017 09:23 AM
Super User
Posts: 17,819

Re: Proc Export to CSV issue - need to change csv tab name

A CSV file is a comma separated text file with no concepts of sheets or tabs. Excel is the default viewer for CSV files, but it should be a text editor really. When Excel opens a CSV file it defaults with creating a Sheet name that is the same as the file name. This is fully Excel behaviour that would have ot be changed via Excel if at all possible.

 

So, no, you can't do what you want via SAS. 

View solution in original post


All Replies
Respected Advisor
Posts: 3,777

Re: Proc Export to CSV issue - need to change csv tab name

[ Edited ]

The issue you describe has nothing to do with the CSV file created by PROC EXPORT.  Your issue is with EXCEL used to open and view the CSV.

Occasional Contributor
Posts: 19

Re: Proc Export to CSV issue - need to change csv tab name

Im just trying to find out if in the dbms section .. if there is a way for SAS to NOT have it so the tab name is the same as the file name, but rather something generic.. I can alter my SAS script so it's using a more generic named file, but I like having the date in the file name if possible

Respected Advisor
Posts: 3,777

Re: Proc Export to CSV issue - need to change csv tab name

CSV is flat file there is no SHEET TAB or TAB name.  That TAB and name is being produced by EXCEL when you use it to open the file.

Solution
‎01-06-2017 09:23 AM
Super User
Posts: 17,819

Re: Proc Export to CSV issue - need to change csv tab name

A CSV file is a comma separated text file with no concepts of sheets or tabs. Excel is the default viewer for CSV files, but it should be a text editor really. When Excel opens a CSV file it defaults with creating a Sheet name that is the same as the file name. This is fully Excel behaviour that would have ot be changed via Excel if at all possible.

 

So, no, you can't do what you want via SAS. 

Super User
Posts: 6,936

Re: Proc Export to CSV issue - need to change csv tab name


hondahawkrider wrote:

Im just trying to find out if in the dbms section .. if there is a way for SAS to NOT have it so the tab name is the same as the file name, but rather something generic.. I can alter my SAS script so it's using a more generic named file, but I like having the date in the file name if possible


Think about it: where in the CSV file would you find the tab name? Answer: nowhere.

This is a pure Excel issue.

If you want to find a workaround in SAS, look at ODS TAGSETS.EXCELXP (to write a report to a named sheet), or LIBNAME EXCEL (to write a pseudo-dataset/sheet into an existing Excel workbook).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 339 views
  • 8 likes
  • 4 in conversation