Creating a Simple Report in SAS

In this post, we will create a simple report using the cars2 data set that we created in the previous exercise.

To Remove Obs Column – add noobs to the PROC PRINT statement.

cars_dataset_sas

results_cars_sas

 

To Print only Selected Variables – use VAR Statement and add only the variables you need. The VAR statement selects the variables that one needs in the reports and determines their order.

cars_dataset_sas

 

To Specify a Condition for Selecting Observations – use WHERE statement. We can also apply WHERE statement to the variables that are not listed in VAR statement. It can be used for both numeric and character variables. However there are some rules for using WHERE statement for character variables: i. enclose the value of the variable in quotation marks. ii. write the value with lowercase and uppercase letter as exactly mentioned in the data set. The following comparison operators can be used with WHERE statement:

SYMBOL

MEANING

EXAMPLE

= or eq equal to  
^= or ne not equal to  cars_dataset_sas
> or gt greater than  cars_dataset_sas
< or lt less than  
>= or ge greater than or equal to  
<= or le less than or equal to  

Suppose we want to list the Audi cars that are priced less than or equal to $30,000, we will use a logical operator AND. We use logical operators with WHERE statement whenever we want to add multiple conditions.

cars_dataset_sas

There are two logical operators that can be used with WHERE statement:

SYMBOL

OPERATOR

MEANING

& AND If both expressions are true, compound expression is true.
! or | or ¦ OR If either of expressions are true, compound expression is true.

When both AND and OR statements are encountered by SAS, it  processes the conditions in a specific order: First, the expressions joined by AND are processed. Then, the expressions joined by OR are processed.

 

Advertisements

One thought on “Creating a Simple Report in SAS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s