Help using Base SAS procedures

Plot Date Interval

Reply
N/A
Posts: 0

Plot Date Interval

Hello,
I have data on days individuals perform an activity set up as follows:

Individual Start Date End Date Total Days
1 10/15/2005 10/18/2005 4
2 11/7/2005 11/30/2005 23
3 12/1/2005 12/2/2005 2

I would like to create a plot where along the x axis we have consecutive days and along the y axis the date interval the activity is being performed. For each individual we would have a response of 1 on dates the activity takes place and 0 when it doesn't, then sum across all individuals for each day. That is, if 20 individuals are active on 11/7, then the y-value is 20 etc. Unfortunately, I am having trouble getting the data set up in a way to do this. Does anybody have any suggestions?
SAS Super FREQ
Posts: 8,743

Re: Plot Date Interval

Hi:
I have 2 suggestions:
1) post your question to the SAS/GRAPH and ODS GRAPHICS Forum
and
2) read the documentation and run the examples for either
---PROC GPLOT
---PROC SGPLOT
and pay close attention to the sample datasets that they use to illustrate their examples. If you compare the structure of the sample datasets to the structure of your data, then you will begin to understand whether your data is "plot-able" in the current structure or whether your data needs to be summarized and/or transformed in order to be plotted.

cynthia
Super Contributor
Super Contributor
Posts: 365

Re: Plot Date Interval

Hello

The following code does the job:

data t;
input Individual StartDate date9. +1 EndDate date9. TotalDays;
format StartDate EndDate date9.;
datalines;
1 15Oct2005 18Oct2005 4
2 07Nov2005 30Nov2005 23
3 01Dec2005 02Dec2005 2
;
run;

data b;
set t;
do i=1 to TotalDays;
if i=1 then date=StartDate-1;
else date+1;
activity=1;
output;
end;
format date date9.;
run;
proc SQL;
create table c as
select date, SUM(activity) as y
from b
group by date
;quit;
Ask a Question
Discussion stats
  • 2 replies
  • 97 views
  • 0 likes
  • 3 in conversation