You log will show more than a single message:
10 data want;
11 set have;
12 array score {3} score1 - score3;
13 array grade {3} grade1 - grade3;
14
15 do i = 1 to 3;
16 if score(i) <= 25 then grade(i) = 'D';
17 else if score(i) <= 50 then grade(i) = 'C';
18 else if score(i) <= 75 then grade(i) = 'B';
19 else if score(i) <= 100 then grade(i) = 'A';
20 else grade(i) = "-";
21 end;
22 drop i;
23
24 run;
NOTE: Character values have been converted to numeric
values at the places given by: (Line):(Column).
16:10 16:30 17:13 17:33 18:13 18:33 19:13 19:36
20:10
NOTE: Invalid numeric data, 'D' , at line 16 column 41.
NOTE: Invalid numeric data, 'C' , at line 17 column 44.
NOTE: Invalid numeric data, 'B' , at line 18 column 44.
id=1 score1=25 score2=50 score3=75 grade1=. grade2=. grade3=. i=4 _ERROR_=1
_N_=1
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
id=2 score1=100 score2=90 score3=80 grade1=. grade2=. grade3=. i=4
_ERROR_=1 _N_=2
NOTE: Invalid numeric data, 'D' , at line 16 column 41.
NOTE: Invalid numeric data, 'C' , at line 17 column 44.
NOTE: Invalid numeric data, 'B' , at line 18 column 44.
id=3 score1=17 score2=33 score3=72 grade1=. grade2=. grade3=. i=4 _ERROR_=1
_N_=3
NOTE: Invalid numeric data, 'B' , at line 18 column 44.
NOTE: Invalid numeric data, 'C' , at line 17 column 44.
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
id=4 score1=55 score2=43 score3=95 grade1=. grade2=. grade3=. i=4 _ERROR_=1
_N_=4
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
NOTE: Invalid numeric data, 'A' , at line 19 column 47.
NOTE: Invalid numeric data, 'C' , at line 17 column 44.
id=5 score1=76 score2=85 score3=39 grade1=. grade2=. grade3=. i=4 _ERROR_=1
_N_=5
NOTE: There were 5 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 5 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
The way you defined the Grade array creates numeric variables. So you cannot assign any of 'A', 'B' or other character value to them. If the variables do not have a predefined type then the Array statement creates numeric variables.
You can create character variables and avoid the invalid data message with:
array grade {3} $ grade1 - grade3 ;
which will create length 8 character variables. The $ as the first item after the array size indicates that you want character variables. If want a length other than 8, such as 1 to hold a single letter, specify the number of characters after the $.
array grade {3} $ 1 grade1 - grade3 ;
You probably still have a problem if I understand what your code is supposed to do as the missing values for the scores will all end up with letter D. That is because missing is less than 25. Missing is treated as less than any given value. So the first "IF" needs to address the missing. Note that you can test the missing value code by placing a dot in the position of one of the scores in the Have data step.
While the automatic conversions that SAS does can be helpful, you really should address the values so the message about the conversion doesn't appear. To numeric is often not a problem but other characters than digit and decimal may cause other errors. Is there some reason that the Scores are supposed to be character? As a minimum they won't sort well if you have values like 1 to 9 in the data.
... View more