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

I am producing a report on student's grades- how many start a Math or English course (Cohort=1), how many complete it (COMP) and how many have success (PASS). I thought that the section of code below would create  the variable 'PASS' with a value of 1 for each occurrence of  grades A, B, C and S and create a variable 'COMP'  with a value of 1 for every student who finished a course .

Rather than  list all the grades that constitute completion, I thought that I could use the 'not equal' condition for the grades that indicate non-completion  and create a positive counter for students who last to the bitter end.  This code does create the correct PASS values; BUT even though there are students that have grades of 'I', 'NC, and "W", all 10K+ students in the cohort have a 'COMP' variable with a value of 1.  If I  use one grade, i.e., If GRADE~=W" then COMP=1, all students with a 'W' grade have a COMP value of 0 and do not appear in the QUAPROPTER subset.

So what an I doing wrong?  I would bet my ex's alimony that I have used this combination before.

Thanks

F9_GRADES;

               SET IA.CERSGRADES;

          IF TERM=>&COHO_TERM AND CRSE_NO>100 AND (COURSENAME='MAT' OR COURSENAME='ENG');

               IF (GRADE='A' OR GRADE='B' OR GRADE='C' OR GRADE='S') THEN PASS=1; /*SET PASS VAR*/

                         IF ( GRADE~='I' OR GRADE~='NC' OR GRADE~='W' ) THEN COMP=1/*SET COMPELETION VAR*/
          cohort=1

array a(*) _numeric_;

do i=1 to dim(a);

if a(i) = . then a(i) = 0;

end;

drop I;
KEEP SSN TERM COURSE CRSE_NO COURSENAME GRADE GOT COMPLETE PASS;


DATA  QUAPROPTER;/*test if the code works*/

     SET F9_GRADES;

               IF COMPLETE=1;

               PROC FREQ; TABLES COHO PASS COMP GRADE;

RUN;;


1 ACCEPTED SOLUTION

Accepted Solutions
madhatter
Calcite | Level 5

Thanks.  The easier way works.  I ma going to have mull over the logic issue though..

View solution in original post

3 REPLIES 3
ballardw
Super User

Basic logic table negation of an or becomes AND

GRADE~='I' and GRADE~='NC' and GRADE~='W'

Try this for easier to read and maintain code:

if grade in ('A', 'B','C', 'S') then pass=1;

if grade not in ('I', 'NC', 'W') then comp = 1;

madhatter
Calcite | Level 5

Thanks.  The easier way works.  I ma going to have mull over the logic issue though..

Tom
Super User Tom
Super User

This condition  ( GRADE~='I' OR GRADE~='NC' OR GRADE~='W' )  is always true.

The logic issue is easy to see if you just pick a specific value of GRADE and see what happens.

If GRADE is not I , NC or W then it is obviously true since all three sub conditions are true.

But if GRADE = 'I' then (GRADE~='I') is FALSE but the other two conditions are true so the overall condition is TRUE.

Similarly for NC or W.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 845 views
  • 0 likes
  • 3 in conversation