In: Statistics and Probability
You inherited the following SAS program. Add all the necessary
statements to:
a) Create two new variables. Call one OVERALL, computed as the
average of the IQ score, the MATH score, and the SCIENCE score
divided by 500. Call the other GROUP, defined as 1 for IQ scores
between 0 and 100 (inclusive), 2 for IQ cores between 101 and 140
(inclusive), and 3 for IQ greater than 140.
b) Provide a listing of this data set in IQ order.
c) Compute the frequencies for GROUP.
DATA IQ_AND_TEST_SCORES;
INPUT ID 1-3
IQ 4-6
MATH 7-9
SCIENCE 10-12;
DATALINES;
001128550590
002102490501
003140670690
004115510510;
Solution-A:
a) Create two new variables. Call one OVERALL, computed as the average of the IQ score, the MATH score, and the SCIENCE score divided by 500. Call the other GROUP, defined as 1 for IQ scores between 0 and 100 (inclusive), 2 for IQ cores between 101 and 140 (inclusive), and 3 for IQ greater than 140.
use data step to create dataset
sum statement to sum IQ MATH and SCIENCE scores divide by 500 and load it into AVERAGE
with if statement give oconditions
lt--means less than
le-less than or equal to
gt--greater than
SAS CODE:
DATA IQ_AND_TEST_SCORES;
INPUT ID 1-3
IQ 4-6
MATH 7-9
SCIENCE 10-12;
DATALINES;
001128550590
002102490501
003140670690
004115510510
;
RUN;
DATA IQ_AND_TEST_SCORES;
SET IQ_AND_TEST_SCORES;
AVERAGE=(sum(IQ,MATH,SCIENCE)/500);
IF IQ GE 0 AND IQ LE 100 THEN GROUP = 1;
IF IQ GE 101 AND IQ LE 140 THEN GROUP = 2;
IF IQ GT 140 THEN GROUP = 3;
RUN;
proc print data=IQ_AND_TEST_SCORES;
run;
Output:
Solution-b:
use proc sort to sort the dataset by IQ
and use proc print to get the listing report
SAS CODE:
proc sort data=IQ_AND_TEST_SCORES;
by IQ;
run;
proc print data=IQ_AND_TEST_SCORES;
run;
Solution-c:
use proc freq to get the frequencies
proc freq data=IQ_AND_TEST_SCORES;
tables group;
run;
Output: