Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this.

Similar presentations


Presentation on theme: "Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this."— Presentation transcript:

1 Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this on the next slide Create file that does import Nothing happens! Meaning, you don’t see any results, but file is created –Look at import file that is created –Caution – need to worry about formats that are carried along during import. They may not be obvious!

2 Bringing Data into SAS Important Concepts in SAS –Permanent and Temporary datasets (tables) –Libraries Libname class “c:\data\class\fw893”; data species; infile "c:\data\class\fw893\fish_species.txt"; input species_code common $ 12-32 family $ genus $ species $; run; data class.species; infile "c:\data\class\fw893\fish_species.txt"; input species_code common $ 12-32 family $ genus $ species $; run; { { This creates a temporary table named species This creates a permanent table named species in the directory specified in the libname

3 ASCII files –May seem a bit harder than an Excel file, but more general –First need to examine structure of file so can import properly. I frequently use Notepad or similar simple text editor –Count columns, names of fields, etc. Bringing Data into SAS

4 Fish Species Table example: –Species Code column 1-2 –Common name column 12-32 –Family column 62-75 –Genus column 112-125 –Species column 162-174 Show SAS code Bringing Data into SAS

5 Important “Quirks” –Numeric fields can be imported without specifying column placement –Variables that are alphanumeric are followed by a dollar sign –If alphanumeric data do not have a space between them, AND text is 8 characters or less, you can import without specifying column placement. –Need to be careful if try to read beyond end of line by having too many fields (need to watch for ending fields that are empty) Bringing Data into SAS

6 Once you have a permanent dataset (table) created, you can read it in using the following syntax: Bringing Data into SAS Libname class “c:\data\class\fw893”; data class.species; infile "c:\data\class\fw893\fish_species.txt"; input species_code common $ 12-32 family $ genus $ species $; run; data dummy; set class.species; run; You can think of the “DATA” step as meaning “create the following table” You can think of the “SET” command as meaning “use the following table”

7 In-class exercise/homework Import the data in sample_list.txt and print out the table in SAS Import the data in sample_list.xls files into SAS and print out the resulting table. How do they compare Try to read in the transect data set (which is a permanent data set) from the class drive, and print off this dataset. Note you will need to specify the correct library name.


Download ppt "Bringing Data into SAS From Menu: –File –Import Data –Spreadsheet example first Pick file by browsing Select Library and Member (we will talk about this."

Similar presentations


Ads by Google