Help using Base SAS procedures

Exporting/Importing CSV file in SAS 9.4

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Exporting/Importing CSV file in SAS 9.4

I’m wondering if we have any possibility to export/import data to/from CSV files from LINUX SAS to Windows PC using PC File Server?

 

Please understand the source CSV file must be on Windows PC.

 

We are able to do this successfully with MS Excel and MS Access, but problem is with only CSV.

 

Could you help me in getting this done? I appreciate if you can get sample syntax for this.

 

Note: We can export CSV within LINUX using proc export, but that is not what I am looking for.


Accepted Solutions
Solution
‎09-14-2017 05:03 AM
Contributor
Posts: 28

Re: Exporting/Importing CSV file in SAS 9.4

Test1.pngTest2.pngTest3.png

 

Then you can run code like this.

 

libname test pcfiles server='mypcfileserver.com' port=9621 dsn='mytexter';

 

data test.'mystuff.csv'n ; set sashelp.class;

run;

 

View solution in original post


All Replies
Super User
Super User
Posts: 9,599

Re: Exporting/Importing CSV file in SAS 9.4

Posted in reply to avinashginjupal

I think you misunderstand your problem.  Let me explain:

Excel files (*.xlsx, *.xls etc.) are Microsoft Office proprietary files.  To create these you need the Excel engine to create them.  This is only present on Windows, hence the need to use pcfiles and such like as a fill in for operating systems like Linux which do not have Office.

 

CSV on the other hand is a plain text files delimited by commas.  This file is not proprietary, can be created and read on any system by any program completely freely.  Therefore you do not need to do anything specific to create this file, and why it is far better as a data medium than Excel.

 

To create CSV on any system, you can proc export file="xyz.csv" data=abc; run;, or you could write your own datastep to do it, or any other method you are not constrained in any way.  

Do not confuse CSV as being Excel it is not.  Excel has a module which can read and interpret a CSV but it does not own that file format.

Contributor
Posts: 28

Re: Exporting/Importing CSV file in SAS 9.4

I think I have found the way:

 

The way we can do this is by defining ODBC entries on the Win Server pointing to whatever folder that is that users want to use.

 

Create an ODBC driver entry for a text file and point it to the directory that you want to write to.    Then you use a named literal to create it.

 

Then you can run code like this.

 

libname test pcfiles server='mypcfileserver.com' port=9621 dsn='mytexter';

 

data test.'mystuff.csv'n ; set sashelp.class;

run;

 

Super User
Posts: 23,771

Re: Exporting/Importing CSV file in SAS 9.4

Posted in reply to avinashginjupal

You do need the path, and possibly the TERMSTR option if you're working across OS but otherwise this is a very cumbersome way to access a CSV file.

 

You should be able to do a straight PROC IMPORT using DBMS=CSV

 

proc export data=sashelp.class outfile='path to csv file' dbms=csv replace;run;
Contributor
Posts: 28

Re: Exporting/Importing CSV file in SAS 9.4

I wanted to export/import file from UNIX to WINDOWS (vice versa), if it is locally then no issues it will work but it should work on cross platforms.

Super User
Super User
Posts: 8,120

Re: Exporting/Importing CSV file in SAS 9.4

Posted in reply to avinashginjupal

avinashginjupal wrote:

I think I have found the way:

 

The way we can do this is by defining ODBC entries on the Win Server pointing to whatever folder that is that users want to use.

 

Create an ODBC driver entry for a text file and point it to the directory that you want to write to.    Then you use a named literal to create it.

 

Then you can run code like this.

 

libname test pcfiles server='mypcfileserver.com' port=9621 dsn='mytexter';

 

data test.'mystuff.csv'n ; set sashelp.class;

run;

 


Cool.  

Can you explain more about how you configured the ODBC entry?  Perhaps a screen shot from ODBC Data Sources Administator ?

 

Solution
‎09-14-2017 05:03 AM
Contributor
Posts: 28

Re: Exporting/Importing CSV file in SAS 9.4

Test1.pngTest2.pngTest3.png

 

Then you can run code like this.

 

libname test pcfiles server='mypcfileserver.com' port=9621 dsn='mytexter';

 

data test.'mystuff.csv'n ; set sashelp.class;

run;

 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 1835 views
  • 0 likes
  • 4 in conversation