BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Merdock
Quartz | Level 8

Suppose I have a dataset that looks like the one below where each subject ID can have up to 4 visits (where visit=00 is baseline) and variable disease status across visits (Yes=1, No=0). This means that one subject might have one disease status at one visit but a different status at any of the follow up visits.  For example, say subject ID=002 has disease (status=1) at baseline, then no disease at visits 01, 02, and then disease again at visit=03.

 

The issue: I need to create a graph that shows the change in disease status classification from visit to visit for each individual subject ID. But I am having some trouble visualizing how this might look like.

 

What I’ve done: One obvious way I was thinking of achieving this is, putting the disease status categories (yes=1, no=0) on the Y-axis and visit on X-axis and and then plot line plots for each subject ID.

 

Questions: I tried the code below but I cannot figure out what’s causing the x-axis for ID=011 to not display the visit numbers in order? It shows 00, 02, 03 and 01 as displayed in image below.

Is there any way to make it such that the x-axis displays all 4 visits for all participants, as opposed to only displaying the visits that each participant has?For example, ID=003 only has visits 01 and 02 but instead of the x-axis for this ID showing only those two visits, I’d like it to show all 4 visits, is that possible?

Finally, is this the best way of visualizing this data, especially given the fact that my real dataset has over 100 participants, or are there any other options I should consider?

Any help would be appreciated.

Thanks!

 

data dat;
input ID $ Visit $ Status $;
datalines;
001	00	0
001	01	0
001	02	0
001	03	0
002	00	1
002	01	0
002	02	0
002	03	1
003	01	1
003	02	1
004	00	1
004	02	1
004	03	0
005	00	1
005	01	0
005	02	0
005	03	0
006	02	0
007	00	0
007	01	0
008	00	1
008	02	1
008	03	0
009	00	0
009	01	1
009	02	0
009	03	1
010	00	1
011	01	0
011	03	1
;
run;

title1"Graph of change in status over time";
proc sgpanel data=dat2;
  panelby id/ uniscale=row;
  series x=visit y=status / markers
   	markerattrs=(size=10pt);
run;

Merdock_0-1655509849418.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Fill in the holes in your series and then plot that version of the data.

proc sql ;
  create table skeleton as
  select * 
  from (select distinct id from dat) a
     , (select distinct visit from dat) b
  ;
quit;
data dat2;
  merge skeleton dat;
  by id visit;
run;


proc sgpanel data=dat2;
  panelby id/ uniscale=row;
  series x=visit y=status / markers
    markerattrs=(size=10pt);
run;

 

View solution in original post

22 REPLIES 22
tarheel13
Rhodochrosite | Level 12

your datalines is wrong. can you please try posting it again? 

Merdock
Quartz | Level 8
Just posted it again but it looks the same. It's working and generating the dataset when I paste it into my SAS though, are you having issues with it?
ballardw
Super User

@Merdock wrote:
Just posted it again but it looks the same. It's working and generating the dataset when I paste it into my SAS though, are you having issues with it?

The code you show creates data set DAT. Then graphs data set DAT2. So we really don't know what is in Dat2.

 

Why are you using Visit number as a character value? Series plots are a tad odd for character values on the x axis.

tarheel13
Rhodochrosite | Level 12

I agree. I've worked with a lot of clinical trials data and there is usually a numeric and character visit variable but the numeric one is like 1,2,3,4 etc. Character one would have said "Screening", "Week 16", "Week 24" etc. 

tarheel13
Rhodochrosite | Level 12

look at the data. is this what you intended? doesn't look like it would be to me. 

tarheel13_0-1655548072831.png

 

Tom
Super User Tom
Super User

@tarheel13 wrote:

look at the data. is this what you intended? doesn't look like it would be to me. 

tarheel13_0-1655548072831.png

 


You must have converted the spaces in the data lines into some other character when you copied the code.

tarheel13
Rhodochrosite | Level 12

I did not convert anything. I copied it directly from this website into SAS.

tarheel13
Rhodochrosite | Level 12

@Tom do you use SAS studio? I was. https://support.sas.com/kb/50/929.html I had to add this dlm='09'x to get it to work.

Tom
Super User Tom
Super User

@tarheel13 wrote:

@Tom do you use SAS studio? I was. https://support.sas.com/kb/50/929.html I had to add this dlm='09'x to get it to work.


I always set the SAS editor option to "Substitute spaces for tabs"You should NEVER have tabs in SAS program files.

SAS Studio has a nasty habit of NOT converting the tabs into spaces when you hit the submit button.  Unlike with SAS Display Manager.

tarheel13
Rhodochrosite | Level 12

I work off 2 laptops. I got a SAS license from my school but I am not sure if it goes away after graduation. I am writing from a Mac now and was using SAS ODA. Is this the option you're talking about? I actually wasn't aware of this option until today. So do you indent your code then? And if you do, do you use 3 spaces instead of pressing the tab key? 

tarheel13_0-1655558762077.png

 

Tom
Super User Tom
Super User

When you hit the tab key it does what a tab key used to do on an actual typewriter, it moves to the next tabstop.  It does not insert '09'x codes into the file.

tarheel13
Rhodochrosite | Level 12

that datalines code does not work for me without '09'x and I did select that option I showed you but it didn't change anything for me. makes same print of data that I posted before. 

Tom
Super User Tom
Super User

Make sure you have the option selected (unlike in the photograph you posted).

Re-copy the lines and paste them.  Change the data step to just list the data lines.

 69         data _null_;
 70           input;
 71           list;
 72         datalines;
 
 RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                     
 73         001 00  0

If the tabs are there then something did not work as expected.

What browser are you using?  I am using Chrome on Mac with SAS/Studio from SAS ODA.

 

Note that in my browser I had to scroll the preferences window to find the SAVE button to have the changes registered.

 

You can also add an INFILE statement.

infile datalines expandtabs ;
tarheel13
Rhodochrosite | Level 12

I think this is already resolved as the link I posted explained the problem with SAS studio. I got the data step to work correctly already. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 22 replies
  • 2106 views
  • 8 likes
  • 4 in conversation