Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Licence update

Assign library

Data Step 

Licence

Confirm expiry date using proc setinit; run;

...

Proc contents data=<libref>._all_ <options>;

 

Options

 

Varnum

List   variables in numerical order, otherwise listed as ascending

Position

Lists the   variables in their position in the data set

Short

List the   variables in a row by row format; useful to cut and paste into editor

Out=

Specify   name for output data set

Nods

Useful   when displaying contents of library; prints only the names of the datasets in   a library

Directory

Prints   full contents of every dataset in a library

 

 

PROC PRINT

Creates reports

...

Format <variable><$> <format command >; invokes a predefined format

Where;

 

Options

 

Noobs

Removes   the observation number column; useful if printing with custom ID

Split=' '

Invokes   labels defined in data step

 

 

FORMATTING

Global formatting

...

1000 - high='high';

SAS formats

 

Comma<w.d>

Writes   numeric data with commas and decimals

Dollar<w.d>

Writes   numeric data with $ commas and decimals

Mmddyy10.

Converts   SAS date to 12/31/1990

Ddmmyy10.

Converts   SAS date to 31/12/1990

Ddmmyy8.

Converts   SAS date to 31/12/90

Date7.

Converts   SAS date to 31dec90

Date9.

Converts   SAS date to 31dec19990

Year4.

Converts   SAS date to year

Monyy7.

Converts   SAS date to dec1990

Date11

Converts   SAS date to 31-12-1990

 

 

Length

If reassigning variable names SAS truncates the character limit to length of first level specified

...

IN operator  can be used to pick up equivalent character variables eg if x in('y', 'Y') then y='yes' means that y=yes if x is y or Y

 

Numerical operators

 

Mean

Arithmetic   mean

Sum

Sum or   arguments

Var

Variance

Sin

Sine

Log

Natural   log

SQRT

Square   root

ABS

Absolute   value

 

 

Logical  operators

Modify where expressions: not / and  / or

Eg where city not in ('London', 'Rome','Paris') = city is not London, Rome or Paris

 

Comparison operators

 

Equal to

eq

=

Not equal   to

ne

 

Less than

lt

<

Greater   than or equal

ge

>=

Less than   or equal

le

<=

Equal to   one of a list

in

 

 

Eg where country in ('AU','US') = country either AU or US / where order_type in (1,2,3)  = order type 1,2 or 3

...

Special where operators (can only be used for where)

 

Operator

Definition

Char

num

Contains

Includes   substring

x

 

Between   and

Inclusive   range

x

x

Is null

A missing   value

x

x

Is   missing

A missing   value

x

x

Like

Matches a   pattern

x

 

Where   same and

Augments   original condition

x

x

 

? Can be used instead of contains

...

SAS times are calculated in seconds from midnight on a given day

 

Date functions

 

Month(date)

Extracts   month of a SAS date

Year(date)

Extracts   year of a SAS date

Qtr(date)

Extracts   quarter of SAS date

Weekdays(date)

Extracts   day of week of SAS date, where 1=Sunday

Today ()

Returns   current date as SAS Date

Mdy(month,   day, year)

Creates a   SAS date value from numeric month, day, year

 

 

Arithmetic operators

 

Symbol

Definition

priority

**

Exponentiation

1

      
         
    •  
    •   

multiply

2

/

Division

2

+

Addition

3

      
         
    •  
    •   

subtraction

3

 

 

Misc operators

 

Symbol

Definition

max   (var1, var2… )

use   largest value from either variable

min   (var1, var2… )

use min   value from either variable

sum   (var1, var2… )

use sum   of variables

 

**NB: if one of the variables has a missing value, arithmetic + will return a missing value but sum will return the value of the second variable**

 

Data cleaning functions

 

Upcase

Returns   upper case

Upcase(<variable>)

 

 

CLEANING

Use upcase or lowcase function to convert all levels of a variable to single case style

...

Common styles: printer, journal, ocean, rtf, sasweb

 

Destination

Extension

Viewed in

Listing

 

SAS   output window

Html

Html

Web   browser

Pdf

Pdf

Adode

Rft

Rft

Word

 

 

 

if missing(age) then adult=.;

...