Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Proc Reg : generate new variables from some coefficients

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-13-2020 10:37 AM
(535 views)

Hello,

I have 6 independent variables (A, B, C, D, E, and F)

proc reg data = example;

model y = A B C D E F;

run;

Given that b_A, b_B and b_c are coefficients of A, B and C, respectively.

How can I generate a new variable from

NewVar = y - (b_A)*A - (b_B)*B - (b_C)*C

Thank You

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @Golf

This is untested code:

```
proc reg data = example outest=parameters;
model y = A B C D E F;
run;
data _null_;
set parameters;
call symputx("Intercept", Intercept);
call symputx("b_A", A);
call symputx("b_B", B);
call symputx("b_C", C);
run;
data want;
set example;
newvar = y - (&b_A.)*A - (&b_B.)*B - (&b_C.)*C;
run;
```

Would that meet your expectations?

Best,

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@Golf wrote:

Hello,

I have 6 independent variables (A, B, C, D, E, and F)

proc reg data = example;

model y = A B C D E F;run;

Given that b_A, b_B and b_c are coefficients of A, B and C, respectively.

How can I generate a new variable from

NewVar = y - (b_A)*A - (b_B)*B - (b_C)*C

You want to compute residuals (y – predicted value)?

Add an OUTPUT statement into your PROC REG that asks for residuals to be computed

```
proc reg data = example;
model y = A B C D E F;
output out=residuals r=residual;
run;
```

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

PaigeMiller,

Nope. I don't want predicted value to subtract from y.

I want to use (b_A)*A + (b_B)*B + (b_C)*C to subtract from y as follow:

NewVar = y - (b_A)*A - (b_B)*B - (b_C)*C.

Nope. I don't want predicted value to subtract from y.

I want to use (b_A)*A + (b_B)*B + (b_C)*C to subtract from y as follow:

NewVar = y - (b_A)*A - (b_B)*B - (b_C)*C.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@Golf wrote:

PaigeMiller,

Nope. I don't want predicted value to subtract from y.

I want to use (b_A)*A + (b_B)*B + (b_C)*C to subtract from y as follow:

NewVar = y - (b_A)*A - (b_B)*B - (b_C)*C.

Use PROC SCORE to use the regression coefficients as you show.

Here's an example: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statu...

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @Golf

Why don't you take also estimated parameters for variables D, E and F? Is it a mistake ?

As suggested by @PaigeMiller you can retrieve the residuals in an OUTPUT statement.

Maybe you will need to re-run the model with only A, B and C to get the desired calculation.

NB: for information, you can gather the parameter estimates by specifying the outest= option in the PROC REG statement.

best,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

It is because I am doing Dynamic OLS to obtain cointegration relationship. In this case only some coefficients need to be used instead of all coefficients.

Thanks.

PS Actually, I can estimate all and see the results, then plug in the number. But I'd like if there exist better way than this.

Thanks.

PS Actually, I can estimate all and see the results, then plug in the number. But I'd like if there exist better way than this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi @Golf

This is untested code:

```
proc reg data = example outest=parameters;
model y = A B C D E F;
run;
data _null_;
set parameters;
call symputx("Intercept", Intercept);
call symputx("b_A", A);
call symputx("b_B", B);
call symputx("b_C", C);
run;
data want;
set example;
newvar = y - (&b_A.)*A - (&b_B.)*B - (&b_C.)*C;
run;
```

Would that meet your expectations?

Best,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dear ed_sas_member,

Thank you so much for your helps.

Best,

Thank you so much for your helps.

Best,

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You're welcome @Golf !

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.