Hello,
I've been an SPSS user for a long time now and I am just now learning howto use SAS due to a job prospect. I have been asked to complete the following task, but am having a hard time writing the code to flag each student as a numerator and denominator in the attached data set:
I was able to complete the two tasks and all the others seem pretty straight forward, but I just can't get my code to work for 'Leave Code: 32'.
This is what I wrote based on what instructions say:
data cps.hs_students_enrolled;
set cps.hs_students_enrolled;
if (leave_code = '32') and (verified_transfer = 'YES' or verified_transfer ='UNKNOWN' or leave_date gt '01feb2016'd) and (enrolled = 0) then denom = 0;
else if denom = 1;
if leave_code = '32' and denom = 1 then num = 1;
But when I go through and check some of my observations with that code, they don't seem to be flagging correctly. I would appreciate any help on this!
I've attached my SAS file and a screen shot of the instructions.
It would really help if you provided an example of some of the ones that you think don't code correctly.
Your data set has a Student_unique_id, so you could point to some values with that. Is that data set supposed be a before or after.
if (leave_code = '32') and (verified_transfer = 'YES' or verified_transfer ='UNKNOWN' or leave_date gt '01feb2016'd) and (enrolled = 0) then denom = 0; else if denom = 1;
you want to look closely at the above highlight.
It is actually a good idea on this forum to copy the code and any messages from the LOG. Paste the copied text into code box opened with the {I} or "running man" icon to prevent the main message window from reformatting the text. That way we know which code you actually ran.
BTW, while learning to use SAS do NOT use this structure:
data cps.hs_students_enrolled; set cps.hs_students_enrolled;
while syntactically valid the result is that your original data set is completely replaced. So if you have a logic error that is not a run-time error you can replace your variables with incorrect values and have to go back to previous steps to recover your input set.
You will find that most of use don't use that at all in production work for mostly that reason.
And another bit, if you want to compare one variable to a list of values use the IN operator:
verified_transfer in ( 'YES' 'UNKNOWN' )
Also, in future please do not post identical questions in multiple parts of this forum. If the question is in the wrong place we will move it. Multiple threads means that in complex topics people will ask the same questions for clarification, meaning we expect you to answer those questions multiple times. Sometimes information on one thread is not provided in another. And people searching this forum for answers may find similar topics but not the solution.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.