Hi,
New SAS user here!
I'm trying to create a new variable based on the max of another variable associated with unique student IDs. Here's an example of the dataset. I'm trying to create the variable titled "MaxTerm". How would I specify that I'm looking for the max term for each student ID?
Thanks the help!
Student_ID | Term | MaxTerm |
000001 | 1 | 4 |
000001 | 2 | 4 |
000001 | 3 | 4 |
000001 | 4 | 4 |
000002 | 1 | 5 |
000002 | 2 | 5 |
000002 | 3 | 5 |
000002 | 4 | 5 |
000002 | 5 | 5 |
proc sql;
create table want as
select *, max(term) as max_term
from have
group by student_id
;
quit;
Is your Maxterm variable numeric or character? If character you my get unexpected results.
Example:
data junk; x='15'; output; x='5'; output; run; proc sql; select max(x) from junk; quit;
will return '5' as the maximum value because when comparing characters '5' is greater than '1'. The second character only comes into consideration when the first character is the same.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.