BookmarkSubscribeRSS Feed
rjacksonbeal
Calcite | Level 5

I need to create a two-way table with the row variable as first surgery and column variable as second surgery per patient per day. I created a counter variable then created the variables CONDX1 and CONDX2 for first and second surgeries, but when I create the table, the values for CONDX2 are all in a separate row. How can I make it so CONDX2 indicates which surgeries were done the same day and for the same patient as those for CONDX1?

Here is my code:  

 

 

PROC SORT DATA=PROJECT.COMPLETE;
BY PT_ID EVENT_DATE;
RUN;

 

DATA VISITSCOUNTER;
SET PROJECT.COMPLETE;
BY PT_ID EVENT_DATE;
IF FIRST.EVENT_DATE=1 THEN VISITS=0;
VISITS+1;
IF LAST.EVENT_DATE=1 THEN OUTPUT;
RUN;

 

DATA Question9;
SET VISITSCOUNTER;
BY PT_ID EVENT_DATE;
IF VISITS=1 THEN CONDX1=CONDX;
IF VISITS=2 THEN CONDX2=CONDX;
RUN;

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

We need to see (a portion of) data set PROJECT.COMPLETE. Please provide the data was working SAS data step code, which you can type in yourself or you can follow these instructions. Do not attach files. Do not provide data as screen captures.

--
Paige Miller
rjacksonbeal
Calcite | Level 5
Obs PT_ID HOSMKG EVENT_DATE CONDX OUTCOME AGE SEX RACE
1 1 0 15951 MI/BYPASS 9 52.341 F 3
2 2 1 15830 MI/PERC 2 28.095 F 3
3 3 0 15767 MI/BYPASS 2 40.785 F 3
4 3 0 15797 MI/BYPASS 2 . F 3
5 4 1 15797 MI/BYPASS 2 47.063 F 3
PaigeMiller
Diamond | Level 26

You say

 

but when I create the table, the values for CONDX2 are all in a separate row. 

and I just don't see that when I run this code, I see CONDX2 never gets assigned a value.

 

PaigeMiller_0-1670266548365.png

 

So either the data you provided is not the same data that is causing the problem, or the code you provided is not the same code that is causing the problem (or both).

--
Paige Miller
rjacksonbeal
Calcite | Level 5
Did I not create CONDX2 with "IF VISITS=2 THEN CONDXX2=CONDX"?
PaigeMiller
Diamond | Level 26

I am running the exact unchanged unedited code you posted. Maybe you posted the wrong code. Maybe the data you provided me doesn't match the data you are using.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 802 views
  • 0 likes
  • 2 in conversation