Thursday, April 20, 2017

SAS Import Wizard (SAS)

In various SAS books, you will be taught methodologies that can be utilized to import foreign file types into SAS. While these methodologies have a certain usefulness, often, unless dealing with a very exotic file structure, SAS’s built in “Import Wizard” should be able accomplish the task of importing.

However, the Import Wizard, being an automated tool, is given the jurisdiction to decide variable length, format, and informat without user discretion. Therefore, running Import Wizard without checking the SAS log and the data set itself, is a risky and reckless proposition. In this article, I will demonstrate how to utilize Import Wizard, and how to effectively modify the code that it provides the user.

First you will need to initiate the Import Wizard. The command to run this tool is located within the SAS Enhanced Editor. From the top left file menu dropdown, choose “Import Data”.


Next, you will be prompted to select the type of data file that you wish to import. I would recommend always using .csv for this particular task.



Next you will be prompted with a screen that asks you to provide the pathway to the file. After you have provided this information, you will encounter another screen that prompts the user to select which SAS Library the new data set should be created in, and what the name of the data set should be.



If the import has been successful, the data should should appear within the SAS library that you selected. Additionally, text should appear within the SAS log that illustrates the code generated by the Import Wizard. This is the code that the Import Wizard created and utilized in its importing task.



Blue text (not shown) should be show beneath the code output in the log. This text indicates record length, the date that the original imported file was created, the maximum record length, the minimum record length, the number of observations, and the number of variables.

Often, as previously mentioned, the Import Wizard may utilize formats and lengths which are either un-suitable for the user's needs, or compromise data integrity. Fortunately, since the code created by the automation is printed to the SAS log, editing the code is possible.

To begin, copy the generated code from the SAS log to a text editor program. Once this has occurred, there are a few step that must be taken before the code can be edited and re-processed.

First, you must delete all of the line numbers listed to the right of the code. Also, all of the system data that is contained between the ‘*’, including the ‘*’ itself must be deleted. Finally, and most importantly, you must delete the singe ‘!’ that is shown in the illustration below. Failure to do so will cause your program to terminate without processing.



Once this has been accomplished, you should be left with code that resembles.



Now you will have the opportunity to modify the variables and their characteristics as you see fit. Once the code editing is complete, copy the code from the text editor back into the SAS Enhanced Editor program window. Run the code. If the code contains no user generated errors, the new data set should overwrite its previous incarnation in the SAS user library.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.