i have table as below
Type course crn meetday meettime NEW COLUMN
2 MAT20 215 MW 09
4 MAT20 154 MW 08 .
4 ACG15 214 T 12 1
4 ACG15 214 MW 12 2
This is an example table. I have first 5 variables 'Type, course, crn , meetday and meettime' I need to add 'new column'.
If course and crn are same , but meetday or meettime different then new column should show the number.
This should do it. Assuming that you have already sorted your data in a way that groups all the course/crn combinations:
data want;
set have;
by course crn notsorted;
if first.crn then do;
if last.crn then new_column=.;
else new_column=1;
run;
else new_column + 1;
run;
Thank you but it is not clear
Well, there are some programming techniques that you may need to know:
Are you asking about those, or are you asking about sorting your data, or are you asking about something else entirely?
no actually, when i use your code it doesn't work. gives error. Should i change somethink?
Hi, another suggestion ...
data x;
input type course :$5. cm meetday:$2. meettime;
datalines;
2 MAT20 215 MW 09
4 MAT20 154 MW 08
4 ACG15 214 T 12
4 ACG15 214 MW 12
;
data y;
do new_column=1 by 1 until (last.cm);
set x;
by course cm notsorted;
if first.cm and last.cm then call missing (new_column);
output;
end;
run;
data set y ...
new_
Obs column type course cm meetday meettime
1 . 2 MAT20 215 MW 9
2 . 4 MAT20 154 MW 8
3 1 4 ACG15 214 T 12
4 2 4 ACG15 214 MW 12
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: