How to Plot a Series of Rates Over Time in SAS

237 Views Asked by At

I have 3 data sets: "Complete", "Incomplete", and "Case_List". "Complete" contains records of individuals that have had a full series of a vaccine; "Incomplete" is identical except that the number of doses is less than the full series; and "Case_List" contains confirmed cases of a specific infection. Each data set contains a date, which I have transformed into week of the year (1:53), the individuals age, which I have divided into age groups(easiest to refer to age groups as 1:8, but their character variables), and an ID. Every ID/record in "Complete" is, by definition, in "incomplete" as the individual received dose 1 before dose 2, but I don't have access to any personal identifiers to link them to the "Case_List" ID's.

I am new to SAS and have yet to find enough instruction on plotting to be able to plot a graph with the Case_List over Week(1:53) overlayed with Incomplete over Week(1:53) and Complete over Week(1:53), and all of that broken down by Age_Group(1:8). If I can't get it figured out, I will just plot everything in R.

Other thoughts: Is it easier to merge Incomplete and Complete so there are only two data sets? Is 8 iterations of a graph that already contains 3 lines going to be too messy for one plot?

Thanks for your help.

1

There are 1 best solutions below

0
On BEST ANSWER

In SAS, you can't overlay plots from multiple datasets - you need to combine everything into one dataset.

You don't have to "merge" anything, though, just set them together and add a "category" variable.

data incompletes completes case_list;
    call streaminit(7);
    do week = 1 to 53;
      do _i = 1 to 200;
        age = rand('Integer',1,8);
        _output = rand('Uniform');
        if _output lt (0.1+week/100) then output completes;
        if _output lt (0.2+week/80) then output incompletes;
        if _output lt (0.2-((week/150)**2)) then output case_list;
      end;
    end;
run;



data total;
  set completes(in=_comp) incompletes(in=_incomp) case_list(in=_case);
  if _comp then category="Complete";
  else if _incomp then category="Incomplete";
  else category="Disease Cases";
run;
    
    

Then you can overlay plots, depending on exactly what you want to do.

proc sgplot data=total;
  vline week/group=category;
run;

You could add paneling by age as noted in the comments, or you have a few other options depending on what exactly you do, but I think this gets at what you really want to know - how do I overlay plots in SAS.