turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Running average score variable based on data getti...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-28-2016 01:19 PM

Working on an assignment and i keep getting an error message.

data scores3;

infile datalines delimiter= '/' dsd;

input StudentID $ Quiz1 Quiz2 Quiz3 Quiz4 Midterm Project Final;

CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

datalines;

JK/89/100/88/91/100/87/87

DS/100/95/97/69/100/88/85

SR/100/84/98/69/0/./89

RL/99/0/94/0/100/77/55

MZ/100/100/92/97/100/100/98

BB/88/./80/52/100/78/76

AC/100/100/100/98/100/100/98

;

run;

proc print data=scores3;

var StudentID CourseAvg;

run;

the above code keeps coming back with an error message and I dont understand what the error in my code is.

61 CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

_____ _____ _____ _____ _______

22 22 22 22 22

61 CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

_______

22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,

LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.

61 CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

_____

22

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN,

LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.

62 datalines;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.SCORES3 may be incomplete. When this step was stopped there were 0 observations and 9 variables.

WARNING: Data set WORK.SCORES3 was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.08 seconds

cpu time 0.07 seconds

these are the warning and error messages recieved after inputing the code.

I really dont understand the error in my code. if someone could help that would be greatl appreciated.

Accepted Solutions

Solution

01-28-2016
02:02 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MadQuidd

01-28-2016 01:26 PM - edited 01-28-2016 01:26 PM

MadQuidd wrote:

CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

You have two problem in this statment

- Where is the multiplication sign between numbers

- As you have Missing values you better use the **SUM()** function as it add missing. Not like the **+**

```
CourseAvg = sum(.1*Quiz1 , .1*Quiz2 ,.1*Quiz3 , .1*Quiz4 , .2*midterm , .2*project , .2*final);
```

All Replies

Solution

01-28-2016
02:02 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MadQuidd

01-28-2016 01:26 PM - edited 01-28-2016 01:26 PM

MadQuidd wrote:

CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

You have two problem in this statment

- Where is the multiplication sign between numbers

- As you have Missing values you better use the **SUM()** function as it add missing. Not like the **+**

```
CourseAvg = sum(.1*Quiz1 , .1*Quiz2 ,.1*Quiz3 , .1*Quiz4 , .2*midterm , .2*project , .2*final);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MadQuidd

01-28-2016 01:36 PM

To build on what mohamed said, with this line:

CourseAvg = .1Quiz1 + .1Quiz2 + .1Quiz3 + .1Quiz4 + .2midterm + .2project + .2final;

You are telling SAS to look for a variable called ".1Quiz1", a variable called ".1Quiz2", etc. These are not valid variable names in SAS (which must begin with an English letter or underscore). You need to tell SAS that you are applying a mathematical operation to the variable Quiz1, namely that you want to multiply it by 0.1 (and so on).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MadQuidd

01-28-2016 02:01 PM

Kindly, if you got answers to your questions. Close the thread, by choosing one of the replies as "Accepted Answer".

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MadQuidd

01-29-2016 05:14 AM - edited 01-29-2016 05:21 AM

One more remark (although the thread has been "closed" already ...):

If variable CourseAvg may be used for further processing (e.g. "if CourseAvg>30 then ...") I would strongly recommend to round it to a suitable number of decimals in order to avoid (!) rounding errors (due to numeric representation issues).

Simplified example:

```
data test;
input id quiz1-quiz3;
cards;
1 35 31 29
2 50 20 30
3 82 53 16
;
data eval;
set test;
avg=sum(.1*Quiz1, .2*Quiz2, .7*Quiz3); /* Risky! No rounding! */
length result $10;
if avg>30 then result='Pass';
else if avg<30 then result='Fail';
else if avg=30 then result='Borderline';
run;
proc print data=eval noobs;
format avg best32.;
run;
```

Output:

id quiz1 quiz2 quiz3 avg result 1 35 31 29 30 Fail 2 50 20 30 30 Borderline 3 82 53 16 30 Pass

As you can see, the three fictitious students are assigned three different results. However, their AVG scores should be *exactly equal* to 30 in all three cases (simple calculation, e.g. 8.2+10.6+11.2=30 for ID=3) and, indeed, this is what PROC PRINT shows, even with a very long display format such as BEST32..

The RESULT values of students 1 and 3 are incorrect due to tiny rounding errors from the calculation of AVG, which lead to slight deviations from the mathematically correct results (AVG=30): For the computer, ID 1 has AVG=29.999999999999996447... (hence <30) and ID 3 has AVG=30.000000000000003552... (hence >30).

This severe issue (student 1 could file a lawsuit!) could be avoided easily by defining

`avg=`**round(**sum(.1*Quiz1, .2*Quiz2, .7*Quiz3)**, 1e-9)**;

The small rounding unit (one billionth) is sufficient to flatten the rounding errors (of size 3.55E-15) and would not distort the results either, even if Quiz1-Quiz3 were not integers, but had, say, three decimals.