0% found this document useful (0 votes)
91 views

SAS Ka Basics of Programming My Way

ok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

SAS Ka Basics of Programming My Way

ok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Getting Started with Programming in

SAS Studio 3.4

SAS Documentation

The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2015. Getting Started with Programming in
SAS Studio 3.4. Cary, NC: SAS Institute Inc.
Getting Started with Programming in SAS Studio 3.4
Copyright 2015, SAS Institute Inc., Cary, NC, USA
All rights reserved. Produced in the United States of America.
For a hard-copy book: No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the
publisher, SAS Institute Inc.
For a web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at
the time you acquire this publication.
The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the
publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or
encourage electronic piracy of copyrighted materials. Your support of others' rights is appreciated.
U.S. Government License Rights; Restricted Rights: The Software and its documentation is commercial computer
software developed at private expense and is provided with RESTRICTED RIGHTS to the United States Government. Use,
duplication or disclosure of the Software by the United States Government is subject to the license terms of this Agreement
pursuant to, as applicable, FAR 12.212, DFAR 227.7202-1(a), DFAR 227.7202-3(a) and DFAR 227.7202-4 and, to the extent
required under U.S. federal law, the minimum restricted rights as set out in FAR 52.227-19 (DEC 2007). If FAR 52.227-19 is
applicable, this provision serves as notice under clause (c) thereof and no other notice is required to be affixed to the
Software or documentation. The Government's rights in Software and documentation shall be only those set forth in this
Agreement.
SAS Institute Inc., SAS Campus Drive, Cary, North Carolina 27513-2414.
July 2015
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute
Inc. in the USA and other countries. indicates USA registration.
Other brand and product names are trademarks of their respective companies.

Contents
Using This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Chapter 1 Introduction to SAS Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Welcome to SAS Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


SAS Studio at a Glance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Chapter 2 First Steps in SAS Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Write a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Save Your Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
What If I Have an Error? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 3 Save Time with the Libraries Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Add Column Names to Your Program . . . . . . . . . . . . . . . . . . . . . . . . 11


Chapter 4 Use SAS Studio to Generate Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Let SAS Studio Do the Programming for You! . . . . . . . . . . . . . . . . . 15


Chapter 5 Additional Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21


Recommended Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

iv Contents

Using This Book


Audience
This book is intended for users who are new to SAS or for experienced programmers
who want to learn about SAS Studio. No SAS programming experience is required to
use this book.

Requirements
To complete the examples in this book, you must have access to SAS Studio 3.4.

vi Using This Book

vii

Accessibility
For information about the accessibility of this product, see Accessibility Features of SAS
Studio 3.4 at support.sas.com.

viii Using This Book

1
Introduction to SAS Studio
Welcome to SAS Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
SAS Studio at a Glance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Welcome to SAS Studio


Welcome to SAS Studio! This document is a short introduction to SAS Studio and
covers how to perform basic programming tasks in SAS Studio. You can follow these
steps and use the sample data in the Sashelp library that is shipped with SAS software.
Many people program in SAS by using an application on their PC desktop or SAS
server. SAS Studio is different because it is a tool that you can use to write and run SAS
code through your web browser. With SAS Studio, you can access your data files,
libraries, and existing programs and write new programs. When you use SAS Studio,
you are also using SAS software behind the scenes. SAS Studio connects to a SAS
server in order to process SAS commands. The SAS server can be a hosted server in a
cloud environment, a server in your local environment, or a copy of SAS on your local
machine. After the code is processed, the results are returned to SAS Studio.

Chapter 1 / Introduction to SAS Studio

SAS Studio supports multiple web browsers, such as Microsoft Internet Explorer, Apple
Safari, Mozilla Firefox, and Google Chrome.
As you work through this document, you will learn how to perform these tasks:
n

write a program

save your results

correct a programming error

use the Libraries section to save time

use SAS Studio to write a program for you

SAS Studio at a Glance


When you sign on to SAS Studio, the main SAS Studio window opens.

SAS Studio at a Glance

The main window of SAS Studio consists of a navigation pane on the left and a work
area on the right. The navigation pane provides access to files on your server and your
folder shortcuts, your tasks and snippets, the libraries that you have access to, and your
file shortcuts. The Server Files and Folders section is displayed by default.
The work area is used to display your data, code, logs, and results. When you first open
SAS Studio, the work area displays a new program window. When you open data and
run tasks, other windows open in the work area with a tabbed interface.
SAS Studio includes two different perspectives: the SAS Programmer perspective and
the Visual Programmer perspective. A perspective is a predetermined set of features
that is customized to meet the needs of a specific type of user. This document is about
programming in SAS, so you need to make sure that the SAS Programmer perspective
is selected on the toolbar at the top of the application. You can find more information
about both perspectives in SAS Studio: User's Guide.
There are several ways that you can get help with your work in SAS Studio. Pop-up
help is available for some options in the application, which you can access by clicking
next to the option. Comprehensive help for SAS Studio is available by clicking
above the work area and selecting SAS Studio Help.

Chapter 1 / Introduction to SAS Studio

2
First Steps in SAS Studio
Write a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Save Your Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
What If I Have an Error? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Write a Program
It is easier than ever to program in SAS. All you need to do is open your browser, start
SAS Studio, and start writing your program. As you enter your code, youll notice that
SAS Studio has several features to help you reduce your programming time, including
autocomplete for hundreds of SAS statements and procedures as well as built-in syntax
help that includes links to the more extensive SAS Product Documentation.

6 Chapter 2 / First Steps in SAS Studio

To get started, lets write a very simple program that uses a sample SAS table from the
Sashelp library. Open SAS Studio and enter the following code in the Program 1
window that is created automatically for you:
proc print data=sashelp.class;
run;

Notice that each SAS statement must end with a semicolon.


Note: If you need to create a new program window, open the Server Files and Folders
section of the navigation pane. Then click and select SAS Program.
To run the code, click
on the toolbar. The Results tab opens automatically with a
listing of the data in the Class table.

Save Your Results

Save Your Results


The results in SAS Studio are easy to use, but what if you need them in a different
format so that you can share them with someone else? By clicking a button on the
Results toolbar, you can download your results to any of three different formats and
save them or open them in the default application for that format:
n

HTML file

PDF file

RTF file

In the following example, the results have been downloaded as a PDF file and opened
in Adobe Acrobat Reader.

8 Chapter 2 / First Steps in SAS Studio

You can also print your results from SAS Studio by clicking
. The results open in a
separate browser window, and you can then use the default printer controls for that
browser.

What If I Have an Error?


If you have an error in your SAS code, SAS Studio makes it easy to identify the
problem. Lets add an error to your original program and see how it works.
Click the Code tab to open your program. Delete the semicolon from the first line of the
program.
Your program should look like this:
proc print data=sashelp.class
run;

Click
to run the program. This time, the Log tab opens automatically to show you
that you have an error.

What If I Have an Error? 9

In the Errors, Warnings, Notes section, expand Errors to view a description of the error.
Click the error message, and SAS Studio highlights it for you in the log so that you can
see exactly where the error occurred.

You can return to your program and correct the error. However, if you have a very long
and complicated program that has a lot of errors, you might want to return to an earlier
version of your program in which you knew all the code was correct. SAS Studio
maintains a log, or submission history, with entries for each time you run a program, so
you can easily return to an earlier version of a program.

10 Chapter 2 / First Steps in SAS Studio

To find an earlier version of your program, click the Code tab to view the current version
of your program. On the toolbar, click

and then click the first version of the program.

The original version of your program opens in a new window from which you can copy
and paste the error-free code into your original program or into a new program.

11

3
Save Time with the Libraries Section
Add Column Names to Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Add Column Names to Your Program


SAS Studio is designed to help you write your SAS programs as quickly and accurately
as possible. From the Libraries section of the navigation pane, you can access all of
your libraries and the tables in the libraries. If you want to see the names of the columns
in a table, you can expand the table and view all of the columns. You can save time
when you are writing a program by dragging items from the Libraries section to your
program. SAS Studio adds code for the dragged items to your program for you.
To see how this works, lets go back to the original program that you started with:
proc print data=sashelp.class;
run;

Next, add the VAR statement to the program to specify which variables, or columns, to
include in the results. After the first line of code, add the following new line of code:
var

Your program should look like this:


proc print data=sashelp.class;
var
run;

12 Chapter 3 / Save Time with the Libraries Section

Now you can use the Libraries section to help complete the VAR statement. Click the
Libraries section in the navigation pane and expand the Sashelp library. Locate the
Class table and expand it to view the columns.

Add Column Names to Your Program

13

Hold down the Ctrl key and select the Name, Age, and Height columns and then drag
them to the end of the VAR statement in your program. A green check mark icon
indicates where you can drop the selected columns.

When you drop the selected columns, SAS Studio adds the column names to your
program. The SAS programming language requires that each statement end with a
semicolon. To avoid another error when you run your program, you must add a
semicolon to the end of the VAR statement.

14 Chapter 3 / Save Time with the Libraries Section

By using the Libraries section, you can easily see the names of the columns in a table,
and you can save time by dragging table and column names to your programs instead
of entering them.

15

4
Use SAS Studio to Generate Your
Code
Let SAS Studio Do the Programming for You! . . . . . . . . . . . . . . . . . . . . . . 15

Let SAS Studio Do the Programming for


You!
If youre not an experienced SAS programmer or if you need an existing program to
help you get started, SAS Studio can help. You can open a table in the table viewer,
select which columns to display, and filter and sort the data. Behind the scenes, SAS
Studio writes all the code that is needed to display the table and makes that code
available to you.
From the Libraries section, double-click the Class table to open it in the table viewer.

16 Chapter 4 / Use SAS Studio to Generate Your Code

In the Columns area of the table viewer, all of the columns are selected by default.
Clear the Weight column and notice that it is immediately removed from the table
viewer.

Let SAS Studio Do the Programming for You!

17

Next, you can add a filter and sort the data. Right-click the Age column heading, and
select Add Filter. From the list of column values, hold down the Ctrl key and select
three values: 11, 12, 13.

Click Filter. The table viewer is updated and now displays only the rows for ages 11, 12,
and 13.
Note: The filter criteria are displayed at the top of the table viewer. You can click
edit the filter and to delete the filter.

to

18 Chapter 4 / Use SAS Studio to Generate Your Code

Finally, right-click the Height column heading and select Sort Ascending. The table is
sorted by the values of the Height column from smallest to largest.

Let SAS Studio Do the Programming for You!

19

While youve been selecting options and customizing the table to get it just the way you
want it, SAS Studio has been generating SAS code that you can use. To view the code,
on the toolbar. A new program window appears with the code that was used to
click
create the view of the table in the table viewer.

20 Chapter 4 / Use SAS Studio to Generate Your Code

This program is a copy of the code that SAS Studio created and is no longer associated
with the table viewer. Editing this program does not affect the data that is displayed in
the table viewer, and modifying the table viewer does not affect the contents of this
code. You can edit this code, or use it as the basis for another program.

21

5
Additional Information
For More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

For More Information


This document has introduced you to some of the basic features that will help get you
started programming in SAS Studio. What you want to learn next depends on how you
will be using the software. Remember that extensive help is available from the SAS
Studio Help menu and from the SAS Studio Product Documentation page.

22 Chapter 5 / Additional Information

23

Recommended Reading
n

SAS Studio: User's Guide

For a complete list of SAS publications, go to sas.com/store/books. If you have


questions about which titles you need, please contact a SAS Representative:
SAS Books
SAS Campus Drive
Cary, NC 27513-2414
Phone: 1-800-727-0025
Fax: 1-919-677-4444
Email: sasbook@sas.com
Web address: sas.com/store/books

24 Recommended Reading

You might also like