Syntax, subsetting IF
statement:
IF expression;
|
D
. It
is positioned in the DATA step for efficiency: other statements do
not need to process unwanted observations.
data work.stresstest;
set cert.tests;
if tolerance='D';
TotalTime=(timemin*60)+timesec;
run;
proc print data=work.stresstest;
run;
D
must
be enclosed in quotation marks, and it must be the same case as in
the data set.
D
are
displayed and TotalTime was calculated.
Value for TotalTime
|
Resulting Value for
TestLength
|
---|---|
greater than 800
|
Long
|
750 - 800
|
Normal
|
less than 750
|
Short
|
Syntax, IF-THEN statement:
IF expression THEN statement;
|
Long
to
the variable TestLength when the value of TotalTime is greater than
800, add the following IF-THEN statement to your DATA step: data work.stresstest; set cert.tests; TotalTime=(timemin*60)+timesec; retain SumSec 5400; sumsec+totaltime; if totaltime>800 then TestLength='Long'; run;
if status='OK' and type=3 then Count+1; if (age^=agecheck | time^=3) & error=1 then Test=1;
if (age^=agecheck | time^=3) & error=1 then Test=1; if status='S' or cond='E' then Control='Stop';
if not(loghours<7500) then Schedule='Quarterly'; if region not in ('NE','SE') then Bonus=200;
if status='OK' and type=3 then Count+1; if status='S' or cond='E' then Control='Stop'; if not(loghours<7500) then Schedule='Quarterly'; if region not in ('NE','SE') then Bonus=200;
if x=1 or 2;
if x=1 or x=2;
if totaltime>800 then TestLength='Long'; if 750<=totaltime<=800 then TestLength='Normal'; if totaltime<750 then TestLength='Short';
if totaltime>800 then TestLength='Long'; else if 750<=totaltime<=800 then TestLength='Normal'; else if totaltime<750 then TestLength='Short';
Syntax, ELSE statement:
ELSE statement;
|
data work.stresstest; set cert.tests; TotalTime=(timemin*60)+timesec; retain SumSec 5400; sumsec+totaltime; length TestLength $6; if totaltime>800 then TestLength='Long'; else if 750<=totaltime<=800 then TestLength='Normal'; else if totaltime<750 then TestLength='Short'; run; proc print data=work.stresstest; run;
if totaltime>800 then TestLength='Long';
else if 750<=totaltime<=800 then TestLength='Normal';
else put 'NOTE: Check this Length: ' totaltime=;
run;
Syntax, DELETE statement:
DELETE;
To conditionally execute
a DELETE statement, use the following syntax for an IF statement:
IF expression THEN
DELETE;
The expression is evaluated
as follows:
|
data work.stresstest;
set cert.tests;
if resthr<70 then delete;
TotalTime=(timemin*60)+timesec;
retain SumSec 5400;
sumsec+totaltime;
length TestLength $6;
if totaltime>800 then TestLength='Long';
else if 750<=totaltime<=800 then TestLength='Normal';
else if totaltime<750 then TestLength='Short';
run;
proc print data=work.stresstest;
run;
Syntax, DROP=, and KEEP=
data set options:
(DROP=variable(s))
(KEEP=variable(s))
|
data work.stresstest (drop=timemin timesec);
set cert.tests;
if resthr<70 then delete;
TotalTime=(timemin*60)+timesec;
retain SumSec 5400;
sumsec+totaltime;
length TestLength $6;
if totaltime>800 then TestLength='Long';
else if 750<=totaltime<=800 then TestLength='Normal';
else if totaltime<750 then TestLength='Short';
run;
proc print data=work.stresstest;
run;
Syntax, DROP, and KEEP
statements:
DROP variable(s);
KEEP variable(s);
|
data work.stresstest;
set cert.tests;
if tolerance='D';
drop timemin timesec;
TotalTime=(timemin*60)+timesec;
retain SumSec 5400;
sumsec+totaltime;
length TestLength $6;
if totaltime>800 then TestLength='Long';
else if 750<=totaltime<=800 then TestLength='Normal';
else if totaltime<750 then TestLength='Short';
run;
proc print data=work.stresstest;
run;