Sample Project #1 – Accessing external file

Here is the actual example of how to read file using external source, in this case through DropBox.

We will need to identify the location of the folder where we want to access the data file using “libname” statement and name this location with alias for easy access. In this case, I name it as “USCensus”. Do note that we name this library reference as USCensus and it needs to be consistent whenever we want to access the data file throughout the process – unless you want to rename it as something and re-run the statement.

We can then use PROC IMPORT statement to access the actual data file by providing the file name and location of the data file where it is stored and we can refer the datafile with a shorter name, and I named it as “data” in this example – but always remember to include the library reference which is “USCensus” otherwise it will give you an error (i.e. “Library name is not assigned”).

There are several statement options which I have included in the statement below such as:

DBMS, where we can specify the datafile type (e.g. CSV, Excel, etc)

GETNAMES, whether our datafile has header or column names. The default option is YES

Screen Shot 2018-02-11 at 9.13.40 PM

Other options that I did not include this example:

MIXED, whether we want to convert all data values to character (YES) or whether to assign character type to a missing numeric data. The default option is NO

SCANTEXT,  by default SAS will use the longest string found as the column width and NO for maximum column width of 255

SCANTIME, by default SAS will convert only time values to DATE9 format (which we will discuss in later posts) and YES option for TIME8 format which is less often used

USEDATE, the default option is assigning date/time values to DATE9 format and NO or less used option is converting them to DATETIME format

 

Disclaimer: This free datafile was shared and obtained from Kaggle website.

 

Advertisements


Categories: SAS Learning

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: