turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- Segmented regression plot or interrupted time seri...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-07-2016 09:27 AM

Hi!

I have similar data (just a small part of it):

Rate time

7.5 1

7.4 2

7.8 3

7.2 4

8.0 5

7.9 6

8.2 7

I han information that there was a change in policy and it hapend when time=4. I want to plot in one graph rate*time and regression lines (before and after policy was introduce)

How can I do it?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to viollete

03-07-2016 09:45 AM

The way I would do it is to introduce a third column that grouped the data into "before" and "after" the policy change:

```
data rates;
length policy $ 6;
input rate time policy $;
cards;
7.5 1 before
7.4 2 before
7.8 3 before
7.2 4 before
8.0 5 after
7.9 6 after
8.2 7 after
;
run;
proc sgplot data=rates;
reg x=time y=rate / group=policy;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

03-07-2016 09:54 AM - edited 03-07-2016 09:55 AM

Dan has the right idea. For less coding, you can create the indicator variable without changing the data:

policy = (time < 4);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

03-08-2016 04:58 AM

Thanks, it does not do what i want. I would like to see something as the Figure1a in the link below

http://www.cdc.gov/pcd/issues/2013/12_0268.htm

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to viollete

03-08-2016 08:14 AM

You need to use a technique called "scoring the regression model" to add a new value to your data set. You want to add an observation with coordinates x=Xmax and y=(predicted value at XMax).

This will require that you fit the model in one of the regression procedures, such as PROC GLM, and output the predicted value to a SAS data set. The following code provides the main ideas:

```
data rates;
input rate time;
group = (time<4);
cards;
7.5 1
7.4 2
7.8 3
7.2 4
8.0 5
7.9 6
8.2 7
;
/* create scoring observations with
x=XMax and Y=. for the group=1 */
data Fake;
rate=.; time=7; group=1;
run;
/* merge data sets */
data All;
set rates fake;
run;
/* evaluate model; create output data set that contains the
new predicted value for XMax for group=1 */
proc glm data=All plots=fitplot;
class group;
model rate = time group;
output out=FitOut p=pred;
quit;
proc sgplot data=FitOut;
scatter x=time y=rate / group=group;
series x=time y=pred / group=group;
run;
```