BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Abby1
Calcite | Level 5

I am having trouble figuring out how to use select here. I want to use the select statement to make a new variable called 'FGrade', but I am not sure what I can do or what I cannot do with a select statement. It keeps giving me multiple errors, but I am not sure how to fix it. I would appreciate any help. Here is my code so far:

 

data school;
input Age Quiz : $1. Midterm Final;
if Age eq 12 then Grade = 6;
	else if Age eq 13 then Grade = 8;
if Quiz eq 'A' then QuizGrade=95;
else if Quiz eq 'B' then QuizGrade=85;
else if Quiz eq 'C' then QuizGrade=75;
else if Quiz eq 'D' then QuizGrade=70;
else if Quiz eq 'F' then QuizGrade=65;
CourseGrade = (0.2*QuizGrade)+(0.3*Midterm)+(0.5*Final);
*Part c. - Using SELECT statements;
select;
when (CourseGrade ge 97) FGrade = 'A+';
when (CourseGrade ge 93 and le 97) FGrade = 'A';
when (CourseGrade ge 90 and le 93) FGrade = 'A-';
when (CourseGrade ge 87 and le 90) FGrade = 'B+';
when (CourseGrade ge 83 and le 87) FGrade = 'B';
when (CourseGrade ge 80 and le 83) FGrade = 'B';
when (CourseGrade ge 77 and le 80) FGrade = 'C+';
when (CourseGrade ge 73 and le 77) FGrade = 'C';
when (CourseGrade ge 70 and le 73) FGrade = 'C-';
when (CourseGrade ge 67 and le 70) FGrade = 'D+';
when (CourseGrade ge 63 and le 67) FGrade = 'D';
when (CourseGrade ge 60 and le 63) FGrade = 'D-';
when (CourseGrade lt 60) FGrade = 'F';
otherwise;
end;
12 A 92 95
12 B 88 88
13 C 78 75
13 A 92 93
12 F 55 50
13 B 88 82
;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Your code needs a cards; statement after the end; and before the data.

 

Your syntax is wrong in select, it should be (here is one example, you can change the rest of them):

 

when (CourseGrade ge 93 and CourseGrade le 97) FGrade = 'A';

Also, your select statements will assign a 93 to A-, even though you appear to have it in the A category, because your conditions in the select statement overlap, and you probably want to fix that.

 

For your future benefit, when you get errors in the log, SHOW US THE LOG. Show us the entire log of the step where the errors are, in the sequence it appears in the log, with nothing chopped out.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Your code needs a cards; statement after the end; and before the data.

 

Your syntax is wrong in select, it should be (here is one example, you can change the rest of them):

 

when (CourseGrade ge 93 and CourseGrade le 97) FGrade = 'A';

Also, your select statements will assign a 93 to A-, even though you appear to have it in the A category, because your conditions in the select statement overlap, and you probably want to fix that.

 

For your future benefit, when you get errors in the log, SHOW US THE LOG. Show us the entire log of the step where the errors are, in the sequence it appears in the log, with nothing chopped out.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 500 views
  • 1 like
  • 3 in conversation