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
- /
- General Programming
- /
- How can I write equation with many dummies efficie...

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-18-2016 11:17 AM

I need to estimate a model with a lot of dummies (>50) with proc model ( I cannot really use proc glm or proc genmod, because it is actually a simultaneous equation model).

The parameters are defined as py_dmy1-py_dmy100 and the dummy variables are dmy1-dmy100. The equation will look like the following:

eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

eq.z= -z_var + gam1*x1 + gam2*x2 +pz_dmy1*dym1 + ... + pz_dmy100*dmy100;

The trouble is that the part "p_dmy1*dmy1+...+ p_dmy100*dmy100" is too long if I write it mannually. Is there a way to write it more efficiently?

What I tried is the following:

proc model data =xxxx;

parameter beta1 beta2 y_dmy1-py_dmy100 gam1 gam2 pz_dmy1-pz_dmy100;

array py_dmy_s {100} py_dmy1-py_dmy100;

array pz_dmy_s{100} pz_dmy1-pz_dmy100;

array dmy_s {100} dmy1-dmy100;

dmy_part_y=0;

dmy_part_z=0;

do jj=1 to 100;

dmy_part_y=dmy_part_y+py_dmy_s{jj}*dmy_s{jj};

dmy_part_z=dmy_part_z+pz_dmy_s{jj}*dmy_s{jj};

end;

eq.y= -y_var +beta1*x1 +beta2*x2 + dmy_part_y;

eq.z= -z_var +gam1*x1 +gam2*x2 + dmy_part_z;

fit y z /sur;

run;

However, it does not work.

Can you guys give me some suggestion or advice?

Thank you very much.

Accepted Solutions

Solution

02-19-2016
10:43 AM

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

02-18-2016 12:44 PM

You may want to make sure that your parameter line is correct. You have y_dmy1-py_dmy100 where you may want **p**y_dmy1-py_dmy100

I can help build something that looks like: eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

```
%macro mydummy(start=, end=, stem1= , stem2=);
%local str;
%let str=;
%do i = &start %to &end;
%let str = &str + &stem1.&i * &stem2.&i;
%end;
&str
%mend;
%put %mydummy(start=1, end=10, stem1=py_dmy, stem2=dmy);
```

This takes "stem" or common part of your variables and concatenates a loop counter from the values you provide.

NOTE:** the line with only &str INTENTIONALLY does not have a ; at the end. **That is so the value of the macro resolves in line as generated program code.

Use in your equation would look like:

eq. y = - y_var + beta1*x1 + beta2 *x2 %mydummy(start=1,end=100,stem1=py_dmy, stem2=dmy) ;

Change the stems for the other variables.

Again, note there your equation does not want a + before the %mydummy macro call as the macro provides its own starting +.

All Replies

Solution

02-19-2016
10:43 AM

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

02-18-2016 12:44 PM

You may want to make sure that your parameter line is correct. You have y_dmy1-py_dmy100 where you may want **p**y_dmy1-py_dmy100

I can help build something that looks like: eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

```
%macro mydummy(start=, end=, stem1= , stem2=);
%local str;
%let str=;
%do i = &start %to &end;
%let str = &str + &stem1.&i * &stem2.&i;
%end;
&str
%mend;
%put %mydummy(start=1, end=10, stem1=py_dmy, stem2=dmy);
```

This takes "stem" or common part of your variables and concatenates a loop counter from the values you provide.

NOTE:** the line with only &str INTENTIONALLY does not have a ; at the end. **That is so the value of the macro resolves in line as generated program code.

Use in your equation would look like:

eq. y = - y_var + beta1*x1 + beta2 *x2 %mydummy(start=1,end=100,stem1=py_dmy, stem2=dmy) ;

Change the stems for the other variables.

Again, note there your equation does not want a + before the %mydummy macro call as the macro provides its own starting +.