Desktop productivity for business analysts and programmers

Replicating import data wizard steps into sas program

Reply
Contributor
Posts: 58

Replicating import data wizard steps into sas program

Folks,

 

I'm designing a loading program to load a .txt file into sas format and assign labels etc.

 

The .txt file is supposed to be comma delimited, however there appears to be an issue with it. It doesn't seem to be entirely comma delimited. When reading it into sas, half way through the dataset, issues begin to occur.

 

To remedy this, I've attempted to load to the program in using the import data wizard to figure out the structure. Using the import wizard the data is transformed into SAS format perfectly.

 

According to the import wizard the structure is something like this.

 

    INFILE 'C:\SASWORK\_TD11956_CMSASAPP04_\#LN00091'
        LRECL=998
        ENCODING="WLATIN1"
        TERMSTR=CRLF
        DLM='7F'x
        MISSOVER
        DSD ;

 

However, when I attempt to replicate this code for my own loading program, basically I copy and paste of the entire code generated by the wizard, it doesn't appear to do what.

 

Would the following message be the reason why it's not replicating?

 

 Note: In preparation for running the following code, the Import
   Data wizard has used internal routines to transfer the source data
   file from the local file system to SASApp. There is no SAS code
   available to represent this action.
   Some characters embedded within the text file were translated to
   alternative characters so as to avoid transmission errors.

Is there anyway I can replicate these internal routines? 

Super User
Posts: 10,557

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor

Not in a simple way. Use proc import once on the text file, and copy the automatically created data step from the log. Adapt that step until the result meets your expectations.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
SAS Super FREQ
Posts: 830

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor

SAS Enterprise Guide provides a task called "Copy Files" This allows you to either upload or download any type of file.

Adjust the INFILE statement of the DATA Step accordingly.

 

See also https://blogs.sas.com/content/sasdummy/2016/11/14/copy-files-task-moved-menus/ by @ChrisHemedinger

Community Manager
Posts: 3,457

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor
Contributor
Posts: 58

Re: Replicating import data wizard steps into sas program

Posted in reply to ChrisHemedinger

Chris this doesn't appear to work for me?

 

Is there anyway I can see these internal routines?

 

 Note: In preparation for running the following code, the Import
   Data wizard has used internal routines to transfer the source data
   file from the local file system to SASApp. There is no SAS code
   available to represent this action.
Community Manager
Posts: 3,457

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor

No, as it's not SAS code.  But you can use the Copy Files step to copy the file to your SAS session as part of your flow, then run the code from there.

 

flow.png

 

See the "Create SAS program code that you can reuse anywhere" section of this blog post, "Tricks for importing text files in SAS Enterprise Guide".

Super User
Posts: 10,557

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor

@Sean_OConnor wrote:

Chris this doesn't appear to work for me?

 

Is there anyway I can see these internal routines?

 

 Note: In preparation for running the following code, the Import
   Data wizard has used internal routines to transfer the source data
   file from the local file system to SASApp. There is no SAS code
   available to represent this action.

No. "Internal" means this is hardcoded into the C# code of Enterprise Guide itself. You can only see its results by comparing the file you feed into EG to the file you find as #LNxxxx in your WORK location.

Copy the original file to the SAS location, run proc import on it, copy the data step code from the log, and adapt it to your needs.

Or write a data step yourself according to the specification you got with the file.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,334

Re: Replicating import data wizard steps into sas program

Posted in reply to Sean_OConnor

Hi, @Sean_OConnor

 

I just came across this thread, and it's a bit fragmented.

 

To try to clarify:

 

Step 1: Use the "Copy Files" Enterprise Guide task to copy your text dataset from your local PC to your SASApp server. This task doesn't use SAS code; it is internal to EG. However, it can be dropped into your project and reused. You'll need to provide a place on SASApp for EG to put the copied text file.

 

Step 2: From there, use your SAS code with your INFILE statement to read the text dataset into SAS dataset format. You'll need to provide the location to which you copied the text file onto SASApp. This goes onto your INFILE statement.

 

Make sure you've got Step 1 succeeding before you try Step 2.

 

Tom

SAS Super FREQ
Posts: 830

Re: Replicating import data wizard steps into sas program

About importing data: once the file in question is on the SAS server, the Import Data Wizard can also work with files on the SAS server, so you do not necessarily need to code the DATA Step yourself. 

Ask a Question
Discussion stats
  • 8 replies
  • 130 views
  • 0 likes
  • 5 in conversation