Help using Base SAS procedures

Import Files from PC to Unix

Reply
Regular Contributor
Posts: 173

Import Files from PC to Unix

Hello Everyone,

I am trying to 'import' a text file from PC to Unix.  I have tried using the code below with no success.  I wonder if anyone knows a different approach?

Proc Import out = DNL

database= "c:\My Docs\Denials.txt"

DBMS=TAB Replace;

Getnames=Yes;

Datarow=2;

Run;

When I submit this code from Unix it just sits there without generating an error code or any output.  I always end up killing the job later.  Does anyone have any suggestions on how to get data from PC to Unix?  This needs to be done within a SAS program, meaning no manual intervention, as this is an automated process.

I really appreciate any input! Smiley Happy

Super User
Posts: 9,682

Re: Import Files from PC to Unix

Can you post a txt file you imported.

Maybe your txt file is not really txt file, it is a delimiter file. or try.

DBMS=dlm Replace;

delimiter='|' ;

Regular Contributor
Posts: 173

Re: Import Files from PC to Unix

Thank you, Ksharp.

Here is a sample of the text file I am trying to import.  It is tab delimited.  Hence the 'DBMS=TAB replace" in my code.

"ID"  "Client"  "C_Code"

"0001298477"  "743"  "41"

"0003876533"  "654"  "20"

Any suggestions?

Thanks again.

Respected Advisor
Posts: 3,124

Re: Import Files from PC to Unix

Hi,

One possible lazy approach is to using infile statment and pre-assign a large length to include all of your variables.

data dnl;

  infile "c:\My Docs\Denials.txt" dsd dlm='09'x firstobs=2;

  input (ID Client C_Code) (:$15.);

run;

Haikuo

Regular Contributor
Posts: 173

Re: Import Files from PC to Unix

Thank you, HaiKuo.

I ran your code and received an error stating "the physical file does not exist".  It seems to look for the file on the Unix server and can't find it.  This is part an automated program so  manual upload is not preferred.

Any other suggestions?

I really appreciate your help! Smiley Happy

Respected Advisor
Posts: 3,124

Re: Import Files from PC to Unix

So you are running SAS on Unix server. Then you need the correct network mapping address for your txt file, or you need to do FTP. Check SAS docs on "filename ftp".

Haikuo

Regular Contributor
Posts: 173

Re: Import Files from PC to Unix

I have the correct network mapping.  I looked up the FTP stuff and don't really know how it applies to my situation.

Does Proc Import even work on Unix?

Respected Advisor
Posts: 3,124

Re: Import Files from PC to Unix

Well, "c:\My Docs\Denials.txt" does NOT look like a network address to me. Proc import will work the same on Unix as it works on PC, but you do need to input the address that Unix can recognize. "c:\My Docs\Denials.txt" is clearly a windows address.

Haikuo

update: Let me restate it clearly, you need to either map "c:\My Docs\Denials.txt" as a network address that Unix can access, Or you need to use FTP to bring this file to your Unix server.

Regular Contributor
Posts: 173

Re: Import Files from PC to Unix

Thanks for your reply.

Since this is an automated process, both approaches (a Unix-reconizable directory or FTP) will need to require no manual intervention.  That is the part I am having difficulties with.  I can easily FTP the file or run proc import from PC SAS.

Is there a way to automatically FTP a file from a windows directory to a UNIX directory - meaning including it as part of the code?

Thank you.

Respected Advisor
Posts: 3,124

Re: Import Files from PC to Unix

If you can't have your windows address mounted ( this is only need to be done one time), then try the following FTP approach:

Step 1: Make sure your PC or Windows server has FTP server running. Check this with your Windows team, if not, then you need to install FTP server service and make it active. This is only need to be done one time.

Step 2:

filename myfile ftp ' \Denials.txt ' cd= 'c:\My Docs\ '

  user='xxx'

pass=xxx

  host='network name or ip address of your pc or win server'

  recfm=v ;run;

data dnl;

  infile myfile dsd dlm='09'x firstobs=2;

  input (ID Client C_Code) (:$15.);

run;

Good luck,

Haikuo

Super User
Posts: 9,682

Re: Import Files from PC to Unix

I found a problem in your code.

database= "c:\My Docs\Denials.txt"

should be

datafile= "c:\My Docs\Denials.txt"

and your sample data is not delimited by TAB ,but a white space.

Proc Import out = DNL

datafile= "c:\My Docs\Denials.txt"

DBMS=dlm Replace;

Getnames=Yes;

Datarow=2;

delimiter=' ';

Run;

Recommend to use webdev to map your local PC fold to UNIX , then you can directly use this path to import this file into UNIX.

filename x webdev 'your-path' ;

..................

Ksharp

Regular Contributor
Posts: 173

Re: Import Files from PC to Unix

Thank you Ksharp for your suggestion.

I have modified my code according to your suggestion.  The code still sits there without generating any output or errors.

I wonder if my Unix environment has been 'setup' to handle proc import.  Is there some kind of command(s) I need to run in my Unix folder before using proc import?

Super User
Posts: 9,682

Re: Import Files from PC to Unix

"I wonder if my Unix environment has been 'setup' to handle proc import. "

I am afraid that your UNIX is not ready for it . You need the help from your UNIX administrator .

Let him use SIMBA (a software can mount a Windows folder on a UNIX directory ), at that time , you can use the proc import as I suggested.

Good Luck.

Ksharp

Ask a Question
Discussion stats
  • 12 replies
  • 2316 views
  • 0 likes
  • 3 in conversation