



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Sung E. Kim, California State University-Long Beach, Dept of Math and Statistics____
IF Class = ‘senior’;
IF Class = ‘senior’ and Gender = ‘Female’; IF Class = ‘senior’ or Class = ‘junior’; IF Class in (‘senior’,‘junior’);
IF 70 <= Average < 90; IF Average GE 70 & Average LT 90;
IF Gender = ‘M’ THEN OUTPUT MALES; ELSE IF Gender = ‘F’ THEN OUTPUT FEMALES; ELSE Missing(Gender) THEN OUTPUT MISSINGDATA;
WHERE Class = ‘senior’ and Gender = ‘Female’; WHERE Class = ‘senior’ or Class = ‘junior’; WHERE Class in (‘senior’,‘junior’);
Sung E. Kim, California State University-Long Beach, Dept of Math and Statistics____
2.2 Conditional Process
IF and ELSE IF: IF-THEN statement can be used to apply a statement to some part or subset of
observations.
IF conditions THEN statements ; or IF conditions THEN DO; Statements ; END; Multiple conditions can be combined with AND (&) or OR (|). To apply separate statements for more than one groups of observations ELSE IF statement can be used:
IF conditions THEN statements ; ELSE IF conditions THEN statements ; ELSE IF conditions THEN statements ; … For example,
IF missing(Score) THEN Grade = .; ELSE IF Score <= 50 THEN Grade = “D”; ELSE IF Score <= 70 THEN Grade = “C”; ELSE IF Score <= 90 THEN Grade = “B”; ELSE IF Score > 90 THEN Grade = “A”;
IF-THEN statements can be used with INPUT statement.
IF conditions THEN INPUT variable list ; ELSE IF conditions THEN INPUT variable list ;
SELECT-WHEN: Series of IF and ELSE IF statements can be simplified using SELECT-WHEN
statement.
Don’t forget END; at the end. More than one values in when statement can be separated by a comma. For example, WHEN (1,2,3). Above example can be replaced with
Sung E. Kim, California State University-Long Beach, Dept of Math and Statistics____
/* Example2_1 */
/* DATA: 'E\SASCLASS\example2_1.dat'
STAT101 Elementary Statistic Fall 2010 Grade Roster C Gonzalez J 82 60 78 T Chung Sr 92 58 96 I Irwin F 52 69 77 C Reid S 98 92 89 P Lee S 60 48 70 B Washington J 47 63 K Piazza F 87 72 90 M Crafton F 100 74100 A Shulz S 47 61 S Olson F 74 77 75 C Chen S 90 73 68 H Wood F 100 98 */
DATA SASPRAC.roster; INFILE 'E\SASCLASS\example2_1.dat' FIRSTOBS=3 MISSOVER; INPUT NAME $2-14 Class $15-16 Class. (Score1 Score2 Score3)(3.);
ARRAY Test (3) Score1-Score3; DO i = 1 to 3; If missing(Test(i)) then Test(i) =0; END; DROP i;
Average = ROUND(MEAN(Score1,Score2,Score3),1); If Average GE 90 then Grade = "A"; ELSE if Average >= 80 then Grade = "B"; ELSE if Average >= 70 then Grade = "C"; ELSE if Average >= 50 then Grade = "D"; ELSE if Average < 50 then Grade = "F";
SELECT (Grade); WHEN ("A") GP = 4; WHEN ("B") GP = 3; WHEN ("C") GP = 2; WHEN ("D") GP = 1; otherwise GP = 0; END;
LABEL Score1='Midterm I' Score2='Midterm II' Score3='Final' GP='Grade Point'; RUN;
VALUE $class 'F'= 'Freshman' 'S'= 'Sophomore' 'J'= 'Junior' 'Sr'='Seniour'; RUN;
PROC Print LABEL NOOBS U data=SASPRAC.roster;
Sung E. Kim, California State University-Long Beach, Dept of Math and Statistics____
/* Example2_2 */
DATA SASPRAC.sales (DROP = type p);
INPUT @1 type $ @; IF type="@" THEN DO; INPUT @3 Store $10.; Delete; END; RETAIN Store; ELSE IF type ne "@" THEN INPUT p $1-3 d 4-6 unit 7-11 @12 price Dollar7.2;
SELECT (p); WHEN ("011") prod = "CDR50"; WHEN ("012") prod = "DVDR-"; WHEN ("014") prod = "DVDDL"; WHEN ("017") prod = "CDR100"; WHEN ("020") prod = "USB2G"; WHEN ("021") prod = "USB8G"; OTHERWISE; END;
sales=unit*price/d;
FORMAT price Dollar7.2 sales Dollar8.2; LABEL prod="Product Name" d="Survey Duration" unit="Unit sold" price="Unit price" sales="Daily Sales";
DATALINES; @ Kenwood 0110300023601200 0120600065203650 0140300102504190 0170600150702160 0201200056203650 0210900023410100 @ Westside 0110300017801290 0120600025603470 0140300087204090 0170600180701960 0201200114803290 0210900040209900 @ SouthHill 0110300030700900 0120600037403750 0140300087404290 0170600099802045 0201200078403880 0210900041509990 ; RUN;
PROC PRINT LABEL U NOOBS DATA= SASPRAC.sales; RUN;