BookmarkSubscribeRSS Feed
Sean_OConnor
Fluorite | Level 6

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? 

8 REPLIES 8
Kurt_Bremser
Super User

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.

BrunoMueller
SAS Super FREQ

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

ChrisHemedinger
Community Manager

See this post about the "file cleansing process", which you can skip.  And this post about how to create a reusable import step that can work outside of EG.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Sean_OConnor
Fluorite | Level 6

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.
ChrisHemedinger
Community Manager

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Kurt_Bremser
Super User

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

TomKari
Onyx | Level 15

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

BrunoMueller
SAS Super FREQ

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. 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 3732 views
  • 0 likes
  • 5 in conversation