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