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

Hello!

For an assignment, I have a data set that I have to round number grades, and then use array and do statements to assign a letter grade.

 

So far I have

 

data hwweek4;

set sasuser.detail;

Math1=round(Math, 1);

Science1=round(Science, 1);

PE1=round(PE, 1);

Reading1=round (reading, 1);

drop math science pe reading;

run;

 

 

Now what I need to do with this data set is to create new columns with a grade for each of these subjects using array and do statements.

If grade is above 90 then Grade= A

If grade is 75-79 then Grade is a B

If Grade is 60-74 then Grade is C

Below 60 but not missing is a D

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

I took the example sashelp.class and developed the code as per your requirement.

 

Please check and update as per your data and test

 

data class;
set sashelp.class;
array grades(2)$ heightgrade weightgrade;
array result1(2) height weight;
array result2(2) height2 weight2;
do i = 1 to 2;
if result1(i) ne . then result2(i)=round(result1(i),1);
if result2(i)>90 then grades(i)='A';
else if 75<=result2(i)<=89  then grades(i)='B';
else if 60<=result2(i)<=74 then grades(i)='C';
else if .<result2(i)<60 then grades(i)='D';
end;
run;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Reeza
Super User

1. Create two arrays for your subjects numerical grade and one for their alphabetical grade

2. Write a series of IF statements for one variable first

2. Add a DO loop around it. 

4. Change the one variable to be arrayName(i) instead. 

 

Or do this in one line with a format. 

 


@klj81 wrote:

Hello!

For an assignment, I have a data set that I have to round number grades, and then use array and do statements to assign a letter grade.

 

So far I have

 

data hwweek4;

set sasuser.detail;

Math1=round(Math, 1);

Science1=round(Science, 1);

PE1=round(PE, 1);

Reading1=round (reading, 1);

drop math science pe reading;

run;

 

 

Now what I need to do with this data set is to create new columns with a grade for each of these subjects using array and do statements.

If grade is above 90 then Grade= A

If grade is 75-79 then Grade is a B

If Grade is 60-74 then Grade is C

Below 60 but not missing is a D

 

 


 

klj81
Fluorite | Level 6

Thanks for the reply. I am very new to SAS and not sure how to create the arrays or do loop.

 

I have been trying to find examples of how to write the code and the proper syntax but have been trouble finding one.

Reeza
Super User

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 


@klj81 wrote:

Thanks for the reply. I am very new to SAS and not sure how to create the arrays or do loop.

 

I have been trying to find examples of how to write the code and the proper syntax but have been trouble finding one.


 

Jagadishkatam
Amethyst | Level 16

I took the example sashelp.class and developed the code as per your requirement.

 

Please check and update as per your data and test

 

data class;
set sashelp.class;
array grades(2)$ heightgrade weightgrade;
array result1(2) height weight;
array result2(2) height2 weight2;
do i = 1 to 2;
if result1(i) ne . then result2(i)=round(result1(i),1);
if result2(i)>90 then grades(i)='A';
else if 75<=result2(i)<=89  then grades(i)='B';
else if 60<=result2(i)<=74 then grades(i)='C';
else if .<result2(i)<60 then grades(i)='D';
end;
run;
Thanks,
Jag
klj81
Fluorite | Level 6

This worked perfectly for me..

thank you so much I really appreciate your help!

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
  • 5 replies
  • 1853 views
  • 1 like
  • 3 in conversation