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

I am trying to create a new variable LetterGrade with recoding GPA into alphabets.

 

However, I keep recieving the message saying variable uninitialized. Below is my code in SAS Studio

 

Please Help!

 

*Creating new variable based on Letter grade;
data Lgrades;
set students_additional;
if 0<gpa<0.5 then LetterGrade=F;
else if 0.5<gpa<1.5 then LetterGrade=D;
else if 1.5<gpa<2.5 then LetterGrade=C;
else if 2.5<gpa<3.5 then LetterGrade=B;
else if gpa >=3.5 then LetterGrade=A;
RUN;
proc print data=Lgrades;
title 'LetterGrade Dataset';
run;
proc contents data=Lgrades;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
nikky
Fluorite | Level 6

Thank you , I will do right away.

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Hi @nikky 

You would need to make recoded values a constant operand within "quotes" rather than variable operand.

 

For eg

if 0<gpa<0.5 then LetterGrade="F";
nikky
Fluorite | Level 6

Thank you , I will do right away.

Tom
Super User Tom
Super User

@nikky wrote:

I am trying to create a new variable LetterGrade with recoding GPA into alphabets.

 

However, I keep recieving the message saying variable uninitialized. Below is my code in SAS Studio

 

Please Help!

 

*Creating new variable based on Letter grade;
data Lgrades;
set students_additional;
if 0<gpa<0.5 then LetterGrade=F;
else if 0.5<gpa<1.5 then LetterGrade=D;
else if 1.5<gpa<2.5 then LetterGrade=C;
else if 2.5<gpa<3.5 then LetterGrade=B;
else if gpa >=3.5 then LetterGrade=A;
RUN;
proc print data=Lgrades;
title 'LetterGrade Dataset';
run;
proc contents data=Lgrades;
run;

 


What values do the variables A, B, C and D have? 

Or did you mean to set the variable to the character stings 'A', 'B', etc instead?

nikky
Fluorite | Level 6

Yes Tom, I do mean to have them in character form.

 

 

Thank you

ballardw
Super User

@nikky wrote:

I am trying to create a new variable LetterGrade with recoding GPA into alphabets.

 

However, I keep recieving the message saying variable uninitialized. Below is my code in SAS Studio

 

Please Help!

 

*Creating new variable based on Letter grade;
data Lgrades;
set students_additional;
if 0<gpa<0.5 then LetterGrade=F;
else if 0.5<gpa<1.5 then LetterGrade=D;
else if 1.5<gpa<2.5 then LetterGrade=C;
else if 2.5<gpa<3.5 then LetterGrade=B;
else if gpa >=3.5 then LetterGrade=A;
RUN;
proc print data=Lgrades;
title 'LetterGrade Dataset';
run;
proc contents data=Lgrades;
run;

 


So what grade do you want to assign with the GPA is exactly 0, 0.5, 1.5 or 2.5 ? You are excluding the end point in every single one of your comparisons with those values. I suspect that you may want

data Lgrades;
set students_additional;
  if 0<gpa<=0.5 then LetterGrade='F';
  else if 0.5<gpa<=1.5 then LetterGrade='D';
  else if 1.5<gpa<=2.5 then LetterGrade='C';
  else if 2.5<gpa<3.5 then LetterGrade='B';
 else if gpa >=3.5 then LetterGrade='A';
 RUN;

or similar

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 4342 views
  • 0 likes
  • 4 in conversation