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.
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;
I'm still getting the error "Variable X1, X2, X3 not found" 😞
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
;
your right I forgot to add the depth column
@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.
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...
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.