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;
Thank you , I will do right away.
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";
Thank you , I will do right away.
@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?
Yes Tom, I do mean to have them in character form.
Thank you
@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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.