SAS notes 1

download SAS notes 1

of 42

Transcript of SAS notes 1

  • 8/6/2019 SAS notes 1

    1/42

    1.Overiew of SASBase/SAS is the core foundation fora variety of data management and

    analytical software componentsoffered by SAS.

  • 8/6/2019 SAS notes 1

    2/42

    1.Overiew of SASBase/SAS provides the essential tools for the

    basic data driven tasks that are commonly

    performed by a programmer. Data access

    Management

    Analysis Presentation.

  • 8/6/2019 SAS notes 1

    3/42

    1.Overiew of SAS

  • 8/6/2019 SAS notes 1

    4/42

    1.Overiew of SASSAS programming language is used to

    Access data from many sources

    Manage your dataAnalyse the data and present it as

    meaningful information in a report that canbe delivered to any platform , in any formatneeded.

    Data access management analysisand presentation

  • 8/6/2019 SAS notes 1

    5/42

    1.Overiew of SASAccessing data:

    SAS can access data

    That is stored almost anywhere whether itis in a file on the system , or the data that isstored on a remote server or in anotherdatabase system.

    That is almost in any format including theraw data sets, SAS data sets and filescreated by other software.

  • 8/6/2019 SAS notes 1

    6/42

    1.Overiew of SASTypes of files that can be accessed:

    Relational databases: DB2, oracle, teradata,

    MS SQL server.

    Non-relational database: ADABAS, PC file

    formats, System 2000 software.

    Enterprise resource planning (ERP) systems:Baan, SAP BW.

  • 8/6/2019 SAS notes 1

    7/42

    1.Overiew of SASManaging data:

    SAS programming language is used to

    manipulate the data .We can use it forformatting the data , creating the variables ,use operators and functions to evaluate,create and recode data values, subset the

    data ,perform conditional processing mergedata sources, create , retrieve and updatedatabase information.

  • 8/6/2019 SAS notes 1

    8/42

    1.Overiew of SASAnalyzing data and presenting

    information:

    Once the data is proper ,SAS is used toanalyze data and produce reports. SAS

    output can range from a simple listing of a

    dataset to customized reports of complexrelationships.

  • 8/6/2019 SAS notes 1

    9/42

    1.Overiew of SASSAS is a powerful data analysis tool. We can

    produce tables , frequency counts and

    cross tabulation tables, create a variety ofcharts and plots, compute a variety of

    descriptive statistics , including mean , sum

    , variance etc, compute correlations and

    other measures of association, as well as

    multi-way cross tabulations and inferential

    statistics.

  • 8/6/2019 SAS notes 1

    10/42

    1.Overiew of SASPresentation:

    SAS has limitless number of visually appealing output formats ,such as,

    An array of markup languages including HTML4 and XML. Output that is formatted for a high resolution printer , such as

    post script , PDF, and PCL files

    RTF

    Color graphs tht can be made interactive using Active X

    controls or Java applets.these can be later sent to a variety of locations and platfoms.

  • 8/6/2019 SAS notes 1

    11/42

    2.Explore SAS workspaceWhen SAS is started ,five main windows

    open.

    The explorer window

    The results window

    The log window

    The editor window

    The output window.

  • 8/6/2019 SAS notes 1

    12/42

    2.Explore SAS workspaceTHE EXPLORER WINDOW:

    This is to view and manage the SAS files and

    create shortcuts to files that are notformatted by SAS. This window is used to

    Create new SAS libraries and SAS files.

    Open any SAS file.

    Perform most file management tasks suchas moving, copying, and deleting files.

    Create shortcuts.

  • 8/6/2019 SAS notes 1

    13/42

    2.Explore SAS workspaceTHE EDITOR WINDOW:

    This window is used to enter, edit, and submit SASprograms. This provides useful editor features like

    Color coding and syntax checking of SASlanguage

    Expandable and collapsible sections

    Recordable macros

    Support for keyboard shortcuts

    Multilevel undo and redo.

  • 8/6/2019 SAS notes 1

    14/42

    2.Explore SAS workspaceTHE LOG WINDOW:

    This displays the messages about the SAS

    session and any SAS programs that aresubmitted.

  • 8/6/2019 SAS notes 1

    15/42

    2.Explore SAS workspaceTHE OUTPUT WINDOW:

    This displays the output from SAS programs

    that are submitted.NOTE: Not all SAS programs create output in

    the output window. Some programs open

    interactive windows. Others producemessages in the log, and few others

    produce in the results viewer window.

  • 8/6/2019 SAS notes 1

    16/42

    2.Explore SAS workspaceTHE RESULTS VIEWER WINDOW:

    This helps to navigate and manage the

    output from SAS programs that aresubmitted.

  • 8/6/2019 SAS notes 1

    17/42

    2.Explore SAS workspaceAlong with all these SAs provides a set of

    ready-to-use solutions , applications and

    tools. These are available in the toolsmenu.

    SAS also has online helpwhich is available

    from the help menu.

  • 8/6/2019 SAS notes 1

    18/42

    3.Work with SAS data setsBefore any work is done , the data has to be in a

    special form called a SAS data set.

    SAS data set (or a table) is a file containingdescriptor information and related data values.

    This is organized as a table of rows

    (observations) and columns (variables) that can

    SAS process. Some SAS datasets also containan index, which enables SAS to locate records in

    the data set.

  • 8/6/2019 SAS notes 1

    19/42

    3.Work with SAS data setsAll SAS files are stored in a SAS library. This

    is a collection of files such as SAS datasets

    and catalogs.To access a library , a name is assigned

    (libref). These are the shortcuts that are

    used to identify libraries during a SAS

    session.

  • 8/6/2019 SAS notes 1

    20/42

    3.Work with SAS data setsView SAS files in a library:

    Go to explorer window

    Double click libraries(see three imp libraries-sashelp, sasuser, work)

    Double click sashelp library

    Scroll down to see several types of files in the library (sas dataset/view/catalog/MDDB)

  • 8/6/2019 SAS notes 1

    21/42

    3.Work with SAS data sets

    Assign a library:

    When a library is defined , location of the

    SAS files to SAS is indicated. Once thelibrary is defined d, SAS files can be

    managed within it.

  • 8/6/2019 SAS notes 1

    22/42

    3.Work with SAS data sets

    On the toolbar , click new library icon

    Type the name of the library

    Select enable at start up

    Click browse and select the location. Click ok

    Assign a library

  • 8/6/2019 SAS notes 1

    23/42

    3.Work with SAS data sets

    Add and rename SAS data set

    With explorer window active select view | show tree. (librariesare displayed)

    Click SAShelp library

    Drag the data set from the right pane and drop it into the desiredlibrary

    Click the library to find the data set in the library. Right click andselect rename and type the new name.

  • 8/6/2019 SAS notes 1

    24/42

    3.Work with SAS data sets

    There are many ways to get data into SAS data set.

    Enter data directly into SAS using view table window

    Read raw data into SAS using import wizard or proc

    statements Read and modify existing data sets using SAS programming

    statements

    Convert other software data files into SAS data set bySAS/Access

    Read other software data directly using SAS/Access

  • 8/6/2019 SAS notes 1

    25/42

    3.Work with SAS data sets

    Open a SAS data set:

    Select the library from the explorer window

    Select the data set that is to be viewed and

    worked on

    Scroll the view table and notice study the

    data values.

  • 8/6/2019 SAS notes 1

    26/42

    3.Work with SAS data sets

    Descriptor portion of SAS:

    The descriptor portion of SAS data set

    contains information about the data set.This includes

    Name of the data set

    Date and time of the creation of the data

    set Number of observations

    Number of variables

  • 8/6/2019 SAS notes 1

    27/42

    3.Work with SAS data sets

    View properties of data set

    Right click on the data set and select

    properties

    Click on the column tab to view the details ofthe variables

    The format of the column can be changedusing format option.

  • 8/6/2019 SAS notes 1

    28/42

    4.Create and run SAS programs

    The SAS language contains

    statements,expressions, functionsand

    CALL routines , options, formats andinformats elements that many

    programming languages share.

  • 8/6/2019 SAS notes 1

    29/42

    4.Create and run SAS programs

    SAS also simplifies programming with its library ofbuilt in programs known as SAS procedures. SASprocedures uses data values from SAS data sets

    to produce preprogrammed reports, requiringminimal effort. BASE/SAS procedures enables to

    Manipulate data

    Store and retrieve information

    Perform statistical analysis Create reports.

  • 8/6/2019 SAS notes 1

    30/42

    4.Create and run SAS programs

    Components of SAS programs:

    SAS basically has two steps the DATA step

    and the PROC step. These two types ofsteps, alone or combined, form all SAS

    programs.

  • 8/6/2019 SAS notes 1

    31/42

    4.Create and run SAS programs

    DATA steps typically create or modify SAS data

    sets. They can also be used to produce custom

    designed reports. Data steps are generally used

    to

    Put the data into SAS data set

    Compute the values for new variables

    Check for and correct errors in the data set. Produce new data sets by subsetting, merging

    and updating existing datasets.

  • 8/6/2019 SAS notes 1

    32/42

    4.Create and run SAS programs

    PROC (procedure) steps typically analyze and process data inthe form of a SAS data set,and they sometimes create SASdata set that contain the results of the procedure. PROCsteps control a library of prewritten routines that perform

    tasks on SAS datasets, such as listing, sorting andsummarizing the data.

    PROC steps are generally used to

    Print a report

    Produce descriptive statistics

    Create a tabular report

    Produce plots and charts

  • 8/6/2019 SAS notes 1

    33/42

    4.Create and run SAS programs

    Characterization of SAS programs:

    SAS programs are made up of SAS statements. ASAS statement has two important characteristics-

    It begins with a keyword.

    It ends with a semicolon.

    A data step begins with the keyword DATA and theproc step begins with keyword PROC. Ends witha RUN statement which tells SAS to process allthe preceding lines of the step.

  • 8/6/2019 SAS notes 1

    34/42

    4.Create and run SAS programs

    SAS statements are free format.

    They can begin and end anywhere on a

    line. One statement can continue over several

    lines

    Several statements can be run on a line.

    SAS statements are not case sensitive.Blanks or special characters separate thewords in a SAS statement.

  • 8/6/2019 SAS notes 1

    35/42

    4.Create and run SAS programs

    Copy a SAS program into the editor window:

    Define the library

    Create the dataset

    Copy a sample SAS program in the editorwindow (notice SAS keywords are colorcoded and the program steps separatedinto expandable blocks.

  • 8/6/2019 SAS notes 1

    36/42

    4.Create and run SAS programs

    Submit the program and view the output:

    When a program is submitted ,SAS compiles and executes thecode and returns any results to the output window.

    With the editor window active select run|submit.

    View the log:

    Each time a step is executed , SAS generates a log ofprocessing activities and the results of the processing. The

    SAS log collects messages about the processing of SASprograms and any errors that may occur.

    Click the log window to activate the log.

  • 8/6/2019 SAS notes 1

    37/42

    4.Create and run SAS programs

    Use the results window:

    Once the output is created , the results

    window opens. The results node at the topof the window contains a folder for the

    output of the procedure. The folder is

    labeled with the procedure name and the

    title of the report.

  • 8/6/2019 SAS notes 1

    38/42

    4.Create and run SAS programs

    Create HTML output:

    Select tools > options > preferences.

    Click the results tab.

    Select the create HTML check box.

    Click ok.

  • 8/6/2019 SAS notes 1

    39/42

    4.Create and run SAS programs

    Modify the program:

    We can add options to the programs to

    Remove the date from the top of eachpage.

    Replace the default the SAS system title.

    Use the column label rather than thecolumn name in the output.

    Remove the obs column.

  • 8/6/2019 SAS notes 1

    40/42

    4.Create and run SAS programs

    To remove date from the top of each page useNODATE system option and paste it at the top ofthe program.

    options nodate; To replace the default title , use TITLE statement.

    title life is beautiful;

    To remove obs column and use column labels,use options on PROC PRINT statement.

    Proc print data=xyz label noobs;

  • 8/6/2019 SAS notes 1

    41/42

    4.Create and run SAS programs

    View and Save results:

    HTML results can be created and saved in HTML files.

    In the results window, scroll the HTML results.

    With results viewer window active, select file > save as. In thefilename box, type the name and click save.

    The results window now shows a new folder for the results of

    the program .double click on the folder to view the output.

  • 8/6/2019 SAS notes 1

    42/42

    4.Create and run SAS programsSave a SAS program and set up a favorite folder:When SAS programs are saved , we can store them in a folder that is easy toaccess from the explorer window.

    With the editor window active, select file > save as.

    This opens to default folder on the system . In filename box , type the name

    and click save. The file is saved with a .sas extension, indicating that it is aSAS program.

    In explorer window, double click favorite folders

    Right click in the favorite folders window and select new favorite folder.

    In the new favorite folder window type , type folder name in the name box.

    Click browse. The select window opens to the same default location where theprogram was saved. Click ok.