Hi all:
I have the below dataset, and plan to output by subject and visit (want) using ODS report, how to do that in DataStep or Proc report ?
Thank you,
data have;
input subject $7. visit $20.;
datalines;
102-001 Visit 1
102-001 Visit 1
102-001 Visit 2
121-002 Visit 1
121-002 Visit 1
121-002 Visit 2
124-003 Visit 2
124-003 Visit 2
124-003 Visit 2
125-002 visit 3
125-002 visit 3
125-002 visit 3
128-002 Visit 2
128-002 Visit 2
128-002 Visit 2
128-002 visit 3
;run;
proc sort;by subject visit;run;
/***want***/
102-001 Visit 1 white
102-001 Visit 1 white
102-001 Visit 2
121-002 Visit 1 white
121-002 Visit 1 white
121-002 Visit 2
124-003 Visit 2 white
124-003 Visit 2 white
124-003 Visit 2 white
125-002 visit 3
125-002 visit 3
125-002 visit 3
128-002 Visit 2 white
128-002 Visit 2 white
128-002 Visit 2 white
128-002 visit 3
So use BY group processing to create your COLORFLAG variable.
It is probably easier to use binary variable, but with some extra IF/THEN logic you could create a text variable if you insist.
data want;
set have;
by subject visit;
retain colorflag 0;
colorflag=mod(colorflag+first.visit,2);
run;
There is no ODS REPORT.
Do you mean PROC REPORT and ODS ____________ ?
Also, can you please explain the logic here, and why you are typing "white" next to some rows and not other rows? Spend some time, give us a complete and clear explanation of the problem and the desired output, instead of the extremely brief explanation you gave.
Hi Paige:
The goal is to color code by subject and visit. the final output look like this when I output as excel , please see attachment or screen shot.
thank you for helping.
Thanks. I don't see an answer to my earlier request:
please explain the logic here, and why you are typing "white" next to some rows and not other rows? Spend some time, give us a complete and clear explanation of the problem and the desired output, instead of the extremely brief explanation you gave.
We're not communicating. I don't think you understand. I still don't see an explanation of the logic that determines which cell gets colored and which don't. I have asked twice for this logic, I don't see it. I have asked twice for "Spend some time, give us a complete and clear explanation of the problem and the desired output, instead of the extremely brief explanation you gave" and I don't see it.
hi all:
data have;
input subject $7. visit $8.;
datalines;
102-001 Visit 1
102-001 Visit 1
102-001 Visit 2
121-002 Visit 1
121-002 Visit 1
121-002 Visit 2
124-003 Visit 2
124-003 Visit 2
124-003 Visit 2
125-002 visit 3
125-002 visit 3
125-002 visit 3
128-002 Visit 2
128-002 Visit 2
128-002 Visit 2
128-002 visit 3
;
run;
proc sort;by subject visit;run;
/*Goal: Need to create a new variable: COLORFLAG using dataset HAVE */
/*The final dataset WANT looks like this */
data want;
input subject $7. visit $8. colorflag $8.;
datalines;
102-001 Visit 1 white
102-001 Visit 1 white
102-001 Visit 2
121-002 Visit 1 white
121-002 Visit 1 white
121-002 Visit 2
124-003 Visit 2 white
124-003 Visit 2 white
124-003 Visit 2 white
125-002 visit 3
125-002 visit 3
125-002 visit 3
128-002 Visit 2 white
128-002 Visit 2 white
128-002 Visit 2 white
128-002 visit 3
;
run;
Thank you,
So use BY group processing to create your COLORFLAG variable.
It is probably easier to use binary variable, but with some extra IF/THEN logic you could create a text variable if you insist.
data want;
set have;
by subject visit;
retain colorflag 0;
colorflag=mod(colorflag+first.visit,2);
run;
Thanks everyone-Paige, Cynthia for your help and time, you rock. this works !!
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.