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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Trouble creating dummy variables

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

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

Posted 11-09-2019 03:39 PM
(603 views)

Hello! I have a data set for types of pond ice and their depths. depth is in meters and ice type is either 'multi-year', 'first-year', or 'landfast'.

I need to create two dummy variables where X2=1 if icetype is 'first year', else X2=0 and X3=1 if icetype is 'multi-year', else X2=0. Landfast is irrelevant for this analysis. also X1=depth. Also, Y=broadband_alb (response)

Heres the code I tried:

```
data ch7hw.prob76;
set problem76;
```

y=broadband_alb;
X1= Depth;
if 'icetype' = 'First-Year' then X2=1; else X2=0;
if 'icetype' = 'Multi-Year' then X3=1; else X3=0;
run;
proc reg;
model y=X1 X2 X3;
run;

But I keep getting errors that say "X1 not found, X2 not found X3 not found..."

I think I'm just formatting it incorrectly. Please help!

Here's a sample of the data:

`broadband_alb`

icetype

0.62 Landfast

0.64 Landfast

First-Year

First-Year

0.56 First-Year

0.59 First-Year

0.67 First-Year

0.52 First-Year

0.62 First-Year

0.50 Multi-Year

0.49 Multi-Year

I would like to add that my data set has many other columns, but these are the only two I'm interested in at the moment.

7 REPLIES 7

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

is icetype a variable or constant. Assuming it's a variable, you wouldn't enclose a variable name in quotes. So please remove the quotes. Quotes are only for **char values.**

```
data ch7hw.prob76;
set problem76;y=broadband_alb;
X1= Depth;
if icetype = 'First-Year' then X2=1; else X2=0;
else if icetype = 'Multi-Year' then X3=1; else X3=0;
run;
```

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

I'm still getting the error "Variable X1, X2, X3 not found" 😞

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

Please post a sample of your input data

In your current sample, I can't see the variable DEPTH

```
DATA have;
input broadband_alb icetype $20.;
cards;
0.62 Landfast
0.64 Landfast
. First-Year
. First-Year
0.56 First-Year
0.59 First-Year
0.67 First-Year
0.52 First-Year
0.62 First-Year
0.50 Multi-Year
0.49 Multi-Year
;
```

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

your right I forgot to add the depth column

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

@valarievil wrote:

I'm still getting the error "Variable X1, X2, X3 not found" 😞

We need to see the ENTIRE log from this program, not just the error messages.

Please copy the log as text (not a screen capture) and then paste it here at the SAS Communities into the window that appears when you click on the {i} icon. **Do not skip this step**.

--

Paige Miller

Paige Miller

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

There are many ways to create dummy variables that are built into SAS, so **YOU DON'T HAVE TO DO IT YOURSELF**.

Many PROCs that do statistical analysis have a CLASS statement, which will create the dummy variables for you. If you do this regression in PROC GLM, the CLASS statement creates the dummy variables for you.

If for some reason (which most beginners don't have), you need a data set to contain the dummy variables, there is PROC GLMMOD and also several other methods, as explained in this long thread https://communities.sas.com/t5/SAS-Procedures/How-can-i-create-dummy-variables-How-can-i-change-my-c...

--

Paige Miller

Paige Miller

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

Unless your homework requires that you use **proc reg**, you would get better results with less effort with** proc glm**. Just drop the data step and do:

```
proc glm data=ch7hw.prob76;
class icetype;
model broadband_alb = depth iceType / solution;
lsmeans iceType / at depth = <some value> pdiff;
run;
```

The lsmeans statement provides comparisons of mean broadband_alb for different iceType values at a given depth. If you suspect that depth effect might not be the same for different iceType values, add the term *iceType*depth* to the model.

PG

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.