Creating and defining new variables


Operators: Character: ' ', " ", ||
Numeric: +, -, *, /, **
Functions (Section 3.2): Character: lowcase, substr, trim, index, length, ...
Date/time: mdy(month, day, year), day, hour, ...
Math: abs, exp, fact, log, log10, mod, sqrt, ...
Probability: cdf, pdf, poisson, probnorm, probt, ...
Quantile: finv, probit, tinv, ...
Random numbers: ranbin, ranexp, ranuni, rannor, ...
Sample statistics: max, min, mean, missing, n, range, std, sum, ...
Trigonometric: sin, arsin, ...
Truncation: ceil, floor, int, round, trunc, ...

Creating a new variable (Section 3.1)
Newvar = expression;
Examples: Creating a date:
classmonth = 01;			
classday   = 12;
classyear  = 2000;
classdate  = mdy(classmonth, classday, classyear);
Another way to define the variable classdate is as follows:
classdate  = '12Jan2000'd;
Notice the "d" after the quoted date text, telling SAS you are defining a date.

Both these methods create a SAS date. SAS dates are the number of days from January 1, 1960. When printed, you will see the value of this variable as a SAS date, unless you format it.

format classdate mmddyy10.;

Using functions over many variables:
Hw1=5; hw2=10; hw3=7;
HWtotal = sum(hw1, hw2, hw3);
Hwavg = mean(hw1, hw2, hw3);

Using the substring function:
Citystate = 'Corvallis, OR';
Comma = scan(citystate, ',');
City = substr(citystate,1,comma-1);
State = substr(citystate, comma+2, length(citystate));