Beruflich Dokumente
Kultur Dokumente
===
SAS Variables:
==============
1. Variable
2. Dataset
3. Format
4. Informat
5. Procedure
6. Option
7. Statement label
8. libref / fileref
9. Catalog entry
10. Array
--> User-defined
_N_
_ERROR_
_FILE_
_INFILE_
_MSG_
_IORC_
_CMD_
8. Index Type
1. LENGTH Statement
2. ATTRIB Statement
4. INPUT statement
7. RETAIN Statement
8. Arrays
ARRAY
ATTRIB
FORMAT
INFORMAT
LENGTH
RETAIN
2. For any of these statements to work, they must be placed prior to any one of the
following declarative statements:
SET
MERGE
UPDATE
Only the variables whose positions are relevant need to be listed. Variables not
listed in these statements retain their original position.
Automatic Variables:
--------------------
_N_
_ERROR_
1. Numbered Range Lists: Only the numbered range list is used in the RENAME=
option.
Numbered range lists require you to have a series of variables with the same name,
except for the last character or characters, which are consecutive numbers.
Var1-Var6
--> Variable :
_NUMERIC_ --> specifies all numeric variables that are already defined in the
current DATA step.
_CHARACTER_ --> specifies all character variables that are already defined in the
current DATA step.
_ALL_ --> specifies all variables that are already defined in the current DATA
step.
Syntax:
-------
------Type----------------------Example--------------------------
Description------------------------------------------------------------------------
---------
Special SAS name lists Function(OF _numeric_) Performs the function on the
_numeric_variable, which specifies all numeric variables that are already defined
in the current DATA step.
---------Statements----------------------------Data Set
Options------------------------------------------------
apply to output data sets only apply to output or input data sets
can be used in DATA steps only can be used in DATA steps and PROC steps
can appear anywhere in DATA steps must immediately follow the name of each
data set to which they apply
2. SET statement
6. WHERE Statement
11. BY statement
1. SELECT
2. FROM
3. WHERE Clause
6. GROUP BY clause
8. HAVING clause
9. ORDER BY clause
1. ENCRYPT= dataset option --> but this option is typically used to encrypt data at
the data set level
2. SAS variable level, you can use a combination of DATA step functions and logic
to create your own encryption and decryption algorithms.
0.3 ^= 0.1*3
3 65,536 8,192
4 16,777,216 2,097,152
5 4,294,967,296 536,870,912
6 1,099,511,627,776
137,438,953,472
7 281,474,946,710,656
35,184,372,088,832
8 (default) 72,057,594,037,927,936
9,007,199,254,740,992
Floating-Point Representation:
------------------------------
Ex: 987=.987*10^3
---- -- -
| | |---> Exponent
Mantissa |--> Base
--> 1byte=8bits
Base 16 2
magnitude
Exponent Bits 7 11
magnitude
Mantissa bits 56 52
precision
character
special numeric
special missing value --> is a type of numeric missing value that enables you to
represent different categories of missing data by using the letters A–Z or an
underscore.
Ex: x=.d;
MISSING Statement
smallest ._ underscore
. period
-n negative numbers
0 zero
Character Variables:
Missing values of character variables are smaller than any printable character
value.
At the beginning of each iteration of the DATA step, SAS sets the value of each
variable that you create in the DATA step to missing, with the following
exceptions:
1. variables named in a RETAIN statement
7. automatic variables
1. When variables are read with a SET, MERGE, or UPDATE statement, SAS sets the
values to missing only before the first iteration of the DATA step.
2. If you use a BY statement, the variable values are also set to missing when
the BY group changes.
1. If you use a missing value in an arithmetic calculation, SAS sets the result
of that calculation to missing.
2. if you use that result in another calculation, the next result is also
missing. This action is called propagation of missing values.
Invalid Operations:
1. dividing by zero
data a;
x=.d;
y=x+1;
put y=;
run;
1. MISSING statement
2. MISSING Option
3. CALL MISSING
4. MISSING FUNCTION
--> You can mix character and numeric variables in the CALL MISSING routine
argument list.
--> Missing values have a value of false when you use them with logical
operators such as AND or OR.
Expressions:
============
1. Expression:
1. constant
2. variable
3. function
2. operands
3. operators
1. character
2. numeric
4. bit testing
name="Tom's"
name='Tom''s'
name="Tom""s"
Ex: '534153'x
2. A comma can be used to make the string more readable, but it is not part of
and does not alter the hexadecimal value.
3. If the string contains a comma, the comma must separate an even number of
hexadecimal characters within the string
--> Any trailing blanks or leading blanks within the quotation marks cause an
error message to be written to the log.
Numeric Constants:
1. Standard Notation
3. Hexadecimal Notation
1 is an unsigned integer
1.2e23 == 1.2*10^23
E --> power of 10
1. T --> time
2. D --> Date
1. You can perform bit testing on both character and numeric variables.
3. When SAS tests a character value, it aligns the left-most bit of the mask
with the left-most bit of the string; the test proceeds through the corresponding
bits, moving to the right.
4. When SAS tests a numeric value, the value is truncated from a floating-point
number to a 32-bit integer.
5. The right-most bit of the mask is aligned with the right-most bit of the
number, and the test proceeds through the corresponding bits, moving to the left.
7. Zeros test whether the bit is off; ones test whether the bit is on; and
periods ignore the bit. Commas and blanks can be inserted in the bit mask for
readability without affecting its meaning.
--> $BINARYw. and BINARYw. formats and the $BINARYw., BINARYw.d, and BITSw.d
informats
d date constant
'01jan04'd
dt datetime constant
'18jan2005:9:27:05am'dt
t time constant
'9:25:19pm't
1. prefix operators
2. infix operators
Arithmetic Operators:
**
Comparison Operators:
= | EQ
^= | NE
¬= | NE
~= | NE
> | GT
< | LT
>= | GE
<= | LE
Numeric Comparisons:
c=5*(x<y)+12*(x>=y);
3. You might get an incorrect result when you compare numeric values of
different lengths because values less than 8 bytes have less precision than those
longer than 8 bytes.
Representation:
1. y = x in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
2. y = x in (1 2 3 4 5 6 7 8 9 10);
3. y = x in (1:10);
Character Comparisons:
Ex: if lastname=:'S';
7. Because printable characters are greater than blanks, both of the following
statements select observations with values of LastName that are greater than or
equal to the letter S:
Ex: if lastname>='S';
if lastname>=:'S';
--> If you compare a zero-length character value with any other character value
in either an IN: comparison or an EQ: comparison, the two-character values are not
considered equal. The result always evaluates to 0, or false.
& | AND
| | OR
! | OR
¦ | OR
¬ | NOT
° | NOT
~ | NOT
1. 0 | . = False
2. 1 = True
1. MIN (><)
2. MAX (<>)
2. The length of the resulting variable is the sum of the lengths of each
variable or constant in the concatenation operation, unless you use a LENGTH or
ATTRIB statement to specify a different length for the new variable.
-
negative prefix 3 z=-(a+b);
° ¬ ~ NOT logical
not 4 if not z
then put x;
/
division f=g/h;
-
subtraction f=g-h;
then c=5;
<= LE less
than or equal to if x le y
then a=0;
= EQ equal
to if y eq (x+a)
then output;
¬= NE not
equal to if x ne z
then output;
>= GE greater
than or equal to if y>=a
then output;
> GT greater
than if z>a
then output;
IN equal
to one of a list if state in
('NY','NJ','PA')
then region='NE';
y = x in (1:10);
then x=1;
then a=d;
1. Because Group I operators are evaluated from right to left, the expression
x=2**3**4 is evaluated as x=(2**(3**4)).
2. The plus (+) sign can be either a prefix or arithmetic operator. A plus sign is
a prefix operation only when it appears at the beginning of an expression or when
it is immediately preceded by an open parenthesis or another operator.
3. The minus (−) sign can be either a prefix or arithmetic operator. A minus sign
is a prefix operator only when it appears at the beginning of an expression or when
it is immediately preceded by an open parenthesis or another operator.
4. Depending on the characters available on your keyboard, the symbol can be the
not sign (¬), tilde (~), or caret (^). The SAS system option CHARCODE allows
various other substitutions for unavailable special characters.
5. For example, the SAS System evaluates -3><-3 as -(3><-3), which is equal to -(-
3), which equals +3. This is because Group I operators are evaluated from right to
left.
6. Depending on the characters available on your keyboard, the symbol that you use
as the concatenation operator can be a double vertical bar (||), broken vertical
bar (¦¦), or exclamation mark (!!).
9. Depending on the characters available on your keyboard, the symbol that you use
for the logical or can be a single vertical bar (|), broken vertical bar (¦), or
exclamation mark (!). You can also use the mnemonic equivalent OR.
SAS date value: --> is a value that represents the number of days between January
1, 1960,
--> SAS date values account for all leap year days, including the
leap year day in the year 2000.
SAS time value: --> is a value representing the number of seconds since midnight of
the current day. SAS time values are between 0 and 86400.
SAS datetime value: --> is a value representing the number of seconds between
January 1, 1960, and an hour/minute/second within a specified date.
PDJULI
--> The YEARCUTOFF= option has no effect on dates that are already stored as
SAS date values.
2. Use the YEARCUTOFF= system option when converting two-digit dates to SAS
date values.
1. SAS can read date and time values that are delimited by the following
characters:
2. Only one delimiter can be used for a date. Otherwise, an error message is
written to the SAS log. For example, 01/Jan/2007 uses a single delimiter
DATE9.
19434 17MAR2013
DAY.
19434 17
DDMMYY.
19434 17/03/13
DDMMYY10.
19434 17/03/2013
DDMMYYB.
19434 17 03 13
DDMMYYB10.
19434 17 03 2013
DDMMYYC.
19434 17:03:13
DDMMYYC10.
19434 17:03:2013
DDMMYYD.
19434 17-03-13
DDMMYYD10.
19434 17-03-2013
DDMMYYN.
19434 17032013
DDMMYYN6.
19434 170313
DDMMYYP.
19434 17.03.13
DDMMYYP10.
19434 17.03.2013
DDMMYYS.
19434 17/03/13
DDMMYYS10.
19434 17/03/2013
DOWNAME.
19434 Sunday
JULDAY. 1
19434 76
JULIAN. 1
19434 13076
MMDDYY.
19434 03/17/13
MMDDYY10.
19434 03/17/2013
MMDDYYB.
19434 03 17 13
MMDDYYB10.
19434 03 17 2013
MMDDYYC.
19434 03:17:13
MMDDYYC10.
19434 03:17:2013
MMDDYYD.
19434 03-17-13
MMDDYYN.
19434 03172013
MMDDYYN8.
19434 03172013
MMDDYYP.
19434 03.17.13
MMDDYYP10.
19434 03.17.2013
MMDDYYS.
19434 03/17/13
MMDDYYS10.
19434 03/17/2013
MMYY.
19434 03M2013
MMYYC.
19434 03:2013
MMYYD.
19434 03-2013
MMYYN.
19434 032013
MMYYP.
19434 03.2013
MMYYS.
19434 03/2013
MONNAME.
19434 March
MONTH.
19434 3
MONYY.
19434 MAR13
PDJULG. 1
19434 2013076F
PDJULI. 1
19434 0100076F
WEEKDATE.
19434 Sunday, March 17, 2013
WEEKDAY.
19434 1
WORDDATE.
19434 March 17, 2013
WORDDATX.
19434 17 March 2013
QTRR.
19434 I
TIMEAMPM.
19434 5:23:54 am
TOD.
19434 05:23:54
YYMM.
19434 2013M03
YYMMC.
19434 2013:03
YYMMD.
19434 2013-03
YYMMP.
19434 2013.03
YYMMS.
19434 2013/03
YYMMN.
19434 201303
YYMMDD.
19434 13-03-17
YYMON.
19434 2013MAR
YYQC.
19434 2013:1
YYQD.
19434 2013-1
YYQP.
19434 2013.1
YYQS.
19434 2013/1
YYQN.
19434 20131
YYQR.
19434 2013QI
YYQRC.
19434 2013:I
YYQRD.
19434 2013-I
YYQRP.
19434 2013.I
YYQRS.
19434 2013/I
YYQRN.
19434 2013I
1. In SAS, a Julian date is a date in the form YYNNN or YYYYNNN, where YY is a two-
digit year, YYYY is a four-digit year, and NNN is the ordinal offset from January 1
of the year YY or YYYY. SAS processes Julian dates only for valid SAS dates.
Date Tasks
HOUR 19434 5
MINUTE 19434 23
MONTH 19434 3
QTR 19434 1
SECOND 19434 54
WEEKDAY 19434 1
SYSDATE9
SYSDATE9 &SYSDATE9 The date at time of SAS
initialization, in the form DDMMMYYYY.
Time Tasks
HOUR. 19434 5
Return the current time of day as a SAS time value Time functions
TIME( ) ( ) The SAS time value at moment
of execution, in the form NNNNN.NNN.
Datetime Tasks
Interval Tasks
01aug60
01jan13
17mar12
365
1. In SAS, a Julian date is a date in the form YYNNN or YYYYNNN, where YY is a two-
digit year, YYYY is a four-digit year, and NNN is the ordinal offset from January 1
of the year YY or YYYY. SAS processes Julian dates only for valid SAS dates.
Syntax:
name<multiple><.starting-point>
1. name --> is the name of the interval. See the following table for a list
of intervals and their definitions.
Single-Unit Intervals:
2. Monday–Monday
3. Tuesday–Tuesday
4. Wednesday–Wednesday
5. Thursday–Thursday
6. Friday–Sunday
--> You can add these lines to your code to fix unmatched comment tags,
unmatched quotation marks, and missing semicolons:
/* '; * "; */;
quit;
run;
--> open and close errors on SAS data sets and other files in
INFILE and FILE statements
--> INPUT statements that do not match the data lines (for
example, an INPUT statement in which you list the wrong columns for a variable or
fail to indicate that the variable is a character variable)
5. macro-related --> macro compile time or execution time, DATA, or PROC step
compile time or execution time
1. SAS performs error processing during both the compilation and the execution
phases of SAS processing.