Академический Документы
Профессиональный Документы
Культура Документы
To program effectively using SAS, you need to understand basic concepts about SAS programs and the SAS files that they process. In particular, you need to be familiar with SAS data sets. In this lesson, you'll examine a simple SAS program and see how it works. You'll learn details about SAS data sets (which are files that contain data that is logically arranged in a form that SAS can understand). Finally, you'll see how SAS data sets are stored temporarily or permanently in SAS libraries.
Editor
This window is a text editor. You can use it to type in, edit, and submit SAS programs as well as edit other text files such as raw data files. In Windows operating environments, the default editor is the Enhanced Editor. The Enhanced Editor is syntax sensitive and color codes your programs making it easier to read and find mistakes. The Enhanced Editor also allows you to collapse and expand the various steps in your program. For other operating environments, the default editor is the Program Editor whose features vary with the version of SAS and operating environment.
Log
The Log window contains notes about your SAS session, and after you submit a SAS program, any notes, errors, or warnings associated with your program as well as the program statements themselves will appear in the Log window.
Output
If your program generates any printable results, then they will appear in the Output window.
Results
The Results window is like a table of contents for your Output window; the results tree lists each part of your results in an outline form.
Explorer
The Explorer window gives you easy access to your SAS files and libraries.
DATA steps 1. Begin with DATA statements 2. Read and modify data 3. Create a SAS data set
PROC steps 1. Begin with PROC statements 2. Perform specific analysis or function 3. Produce results or report
Sample program Data work.clinic; Input Name$ Age Gender$; Cards; Shilpa 23 female Ravi 24 male Pradip 24 male Sweta 23 female Run; Characteristics of SAS Programs
Next let's look at the individual statements in our sample program. SAS programs consist of SAS statements. A SAS statement has two important characteristics:
Sample Program Code a DATA statement DATA work.clinic; a INPUT statement Input Name$ Age Gender$; a CARDS statement Cards; a RUN Statement Run;
Statements
Issue the SUBMIT command or click on Submit or select Run _ Submit to submit the program for execution.
Data types
Raw data come in many different forms, but SAS simplifies this. In SAS there are just two data types: numeric and character. Numeric fields are, well, numbers. They can be added and subtracted, can have any number of decimal places, and can be positive or negative. In addition to numerals, numeric fields can contain plus signs (+), minus signs (-), decimal points (.), or E for scientific notation. Character data are everything else. They may contain numerals, letters, or special characters (such as $ or !) and can be up to 32,767 characters long.
NOTE: The data set WORK.CLINIC has 4 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.31 seconds cpu time 0.00 seconds 8 Run;
Access data in the form of a SAS data set Analyze, manage, or present the data.
Conceptually, a SAS data set is a file that consists of two parts: a descriptor portion and a data portion. Sometimes a SAS data set also points to one or more indexes, which enable SAS to locate records in the data set more efficiently. (The data sets that you work with in this lesson do not contain indexes.)
Length
A variable's length (the number of bytes used to store it) is related to its type.
Character variables can be up to 32K long. All numeric variables have a default length of 8. Numeric values (no matter how many digits they contain) are stored as floating-point numbers in 8 bytes of storage, unless you specify a different length.
Missing data
Sometimes despite your best efforts, your data may be incomplete. The value of a particular variable may be missing for some observations. In those cases, missing character data are represented by blanks, and missing numeric data are represented by a single period (.).
SAS Libraries
Sashelp
A permanent library, that contains sample data and other files which control how SAS works at your site. This is a read-only library.
Sasuser
A permanent library that contains SAS files in the Profile catalogs that store your personal settings. This is also a convenient place to store your own files.
Work
A temporary library for files that do not need to be saved from session to session.
In the New Library window, type the name of the library you want to create. This name is called a libref which is short for library reference. A libref must be eight characters or fewer; start with a letter or underscore; and contain only letters, numerals, or underscores. In this window, the name Mylib has been typed in as the libref. In the Path field, enter the complete path to the folder or directory where you want your data sets to be stored, or choose the Browse button to navigate to the location. If you dont want to define your library reference every time you start up SAS, then check the Enable at startup box. Click OK and then your new library reference will appear in the Active Libraries window. Here is the Active Libraries window showing the newly created Mylib library.
OR Libname Mylib D: \;
- in Editor Window.
Deleting Data sets Proc datasets library = SAS library name; Delete SAS-dataset list; Run; Properties of Data sets
<libref.>SAS-data-set names one SAS data set to process. <libref.>_ALL_ requests a listing of all files in the library. (Use a
period (.) to append _ALL_ to the libref.)
NODS suppresses the printing of detailed information about each file when you
specify _ALL_. (You can specify NODS only when you specify _ALL_.)
Selected Menus (as displayed in the Windows operating environment) Select items from this menu ... To ...
open main SAS windows. From the Explorer window, you can use this menu to show or hide details and a tree view.
submit and recall SAS programming statements in the Program Editor window.
line size (the maximum width of the log and output) page size (the number of lines per printed page of output) The display of page numbers. The display of date and time.
Not all options are available for all operating environments. A list of options specific to your operating environment appears in the SAS Help and Documentation. You can see a list of system options and their current values by opening the SAS System Options window or by using the OPTIONS procedure. To use the OPTIONS procedure, submit the following SAS program and view the results in the SAS log:
Common options
The following are some common system options you might want to use: CENTER | NOCENTER DATE | NODATE Controls whether output are centered or left-justified. Default: CENTER. Controls whether or not todays date will appear at the top of each page of output. Default: DATE. Controls the maximum length of output lines. Possible values for n are 64 to 256. Default varies. Controls whether or not page numbers appear on each page of SAS output. Default: NUMBER.
ORIENTATION = PORTRAIT Specifies the orientation for printing output. ORIENTATION = LANDSCAPE Default: PORTRAIT PAGENO = n PAGESIZE = n Starts numbering output pages with n. Default is 1. Controls the maximum number of lines per page of output. Possible values for n are 15 to 32767. Default varies. Specifies size of margin (such as 0.75in or 2cm) to be printing output. Default: 0.00in.
DATA icecream; INFILE c:\MyRawData\Sales.txt; INPUT Flavor $ 1-9 Location BoxesSold; RUN; Extraction from Excel
Using the Import Wizard1, you can read a variety of data file types into SAS by simply answering a few questions. The Import Wizard will scan your file to determine variable types2 and will, by default, use the first row of data for the variable names. Start the Import Wizard by choosing Import Data from the File menu. Select the type of file you are importing by choosing from the list of standard data sources such as Excel 97, excel 2000, etc...
OR Proc import file = path of excel file out = sas-data set name; Run;
reading observations and variables from existing SAS data sets for further processing in the DATA step concatenating and interleaving data sets, and performing one-to-one reading of data sets Reading SAS data sets by using direct access methods.