Академический Документы
Профессиональный Документы
Культура Документы
Version: 1.0.2
1. You begin with raw data, that is, a collection of data that
has not yet been processed by SAS.
2. You use a set of statements known as a DATA step to get
your data into a SAS data set.
3. Then you can further process your data with additional
DATA step programming or with SAS procedures.
Reading raw data from instream data lines
INFORMATS FORMATS
Informats tell SAS how to read the VS formats tell SAS how to display the
data. data.
Random sample
Select rows by using IF statement
proc surveyselect data=sashelp.cars
data want; method=srs n=10 seed=12345
set sashelp.buy; out=SampleSRS;
if amount >=-1000; run;
Data attributes + columns list Peek at the data set contents
proc datasets ;
Data header (first 5 rows)
contents
data=SASHELP.HEART
order=collate; proc print data=sashelp.class (obs=5);
quit;
+ addition = EQ Equal to
Some SAS
- subtraction ^= NE Not Equal to
Operators
* multiplicatio > GT greater than
n
< LT less than
A SAS operator is a
** exponentiat
ion >= GE greater than symbol that
represents a
or equal to
/ division comparison,
arithmetic
Logical operators <= LE less than or calculation, or logical
equal to operation; a SAS
& AND function; or grouping
parentheses.
| OR
IN is one of
^ NOT
data names;
infile datalines;
input Name$;
If statement
datalines;
Ali
Karam
Roaa
Hala
;
data titles;
set names;
if name="Ali" then
do; SAS evaluates the expression in
title="Papa"; an IF-THEN/ELSE statement to
end; produce a result that is either
else if name="Karam" then nonzero, zero, or missing. A
do;
nonzero and nonmissing result
title="Mama";
end; causes the expression to be true;
else a result of zero or missing causes
title="Kid"; the expression to be false.
data names;
infile datalines; Select statement
input Name$;
datalines;
Ali
Karam
Roaa
Hala
;
data titles;
set names;
select (name); Select VS If:
when ("Ali") title="Papa"; When you have a long series of
when ("Karam") mutually exclusive conditions,
title="Mama"; using a SELECT group is more
otherwise title="Kid"; efficient than using a series of
end; IF-THEN statements because
run; CPU time is reduced.
data df; data df;
do x=1 to 3; do x=1,2,3; DO Statement
y=x**2; y=x**2;
output; output;
end; end;
run; run;
data total;
set sashelp.buy;
TotalAmount + Amount;
A missing value is a valid value in SAS. A missing
character value is displayed as a blank, and a
missing numeric value is displayed as a period.
STDIZE procedure with the REPONLY option can be
Working with
used to replace only the missing values. The missing values
METHOD= option enables you to choose different
location measures such as the mean, median, and
midrange. Only numeric input variables should be
used in PROC STDIZE.
SCAN(char, n, 'delimiters') Returns the nth word Name = "Dr. Ali Ajouz" ;
from a string. title = scan(Name, 1, ".") ;
data result;
merge data1 data2;
run;
We can use IN option in
the MERGE statement Merging data sets on a
with IF statement to
control the output.
common column
data result;
merge data1(in=InData1)
+ data2(in=InData2);
by ID;
/* code here */
I welcome comments,
suggestions and corrections.
aliajouz@gmail.com