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
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!
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.