Use SAS : 2. (a) Write a SAS DATA step to read a series of variables ID, SCORE1
ID: 3605216 • Letter: U
Question
Use SAS :
2. (a) Write a SAS DATA step to read a series of variables ID, SCORE1 and SCORE2 where there are several ID, SCORE1 and SCORE2 per line. Each ‘ID, SCORE1 and SCORE2’ forms one observation. ID is a character variable; SCORE1 and SCORE2 are numeric variables. For the score variables, change the value “N/A” to 0 and change the value “9999” to 100. The name of the data set is Q2_A. Here are the data:
001 N/A 97 003 9999 85 002 98 9999
004 9999 86 005 60 N/A 006 100 100
008 98 9999 010 N/A N/A 009 87 98
011 85 59
.
Explanation / Answer
This example multiplies all the numeric variables in array TEST by 3.
options nodate pageno=1 linesize=80 pagesize=60;
data sales;
infile datalines;
input Value1 Value2 Value3 Value4;
datalines;
11 56 58 61
22 51 57 61
22 49 53 58
;
data convert(drop=i);
set sales;
array test{*} _numeric_;
do i=1 to dim(test);
test{i} = (test{i}*3);
end;
run;
proc print data=convert;
title 'Data Set CONVERT';
run;
The following output shows the CONVERT data set.
Output From Using a _NUMERIC_ Variable List
Data Set CONVERT 1
Obs Value1 Value2 Value3 Value4
1 33 168 174 183
2 66 153 171 183
3 66 147 159 174
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.