1 / 7

Bringing Data into SAS

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

pettit
Download Presentation

Bringing Data into SAS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Bringing Data into SAS • 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.

  4. Bringing Data into SAS • 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

  5. Bringing Data into SAS • 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)

  6. Bringing Data into SAS • Once you have a permanent dataset (table) created, you can read it in using the following syntax: 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.

More Related