I am trying to make a simulated data set for x and y. I was able to create the x but am having trouble making the y. Where I am stuck is there is an intercept between 5 and 10 and a slope between 10 and 20.The below is the code I have used to create x and what I have as a base to create y.
the exact question is:
data norm4 (keep=x);
call streaminit(0);
do i=1 To 20;
x= rand("uniform");
output;
end;
run;
proc reg;
model y=mx+b;
do m=10 To 20 b=5 To 10;
run;
@fanellm1 wrote:
I am trying to make a simulated data set for x and y. I was able to create the x but am having trouble making the y. Where I am stuck is there is an intercept between 5 and 10 and a slope between 10 and 20.The below is the code I have used to create x and what I have as a base to create y.
the exact question is:
The variable y should be a linear function of x with an intercept between 5 and 10 and a slope between 10 and 20. Pleasenote that the intercept and slopes are constants.
data norm4 (keep=x);
call streaminit(0);
do i=1 To 20;
x= rand("uniform");
output;
end;
run;
So, y is a function of x. The formula is y=intercept + slope * x
In your data step, you need to program this. Give it a try.
Thanks Paige!
Do I then need to define the slope and intercept somewhere?
Yes or no. Either. Depends on what you mean by "define". Give it a try.
Paige,
This is what I tried:
data norm4 (keep=x);
call streaminit(0);
do i=1 To 20;
x= rand("uniform");
output;
end;
run;
but am getting the error:
Show us the actual SAS log, the entire log, not just the error messages. Please click on the {i} icon and paste your log as text into that window, this maintains the spacing and formatting in the log and makes it easier for us to view and understand.
Paige,
Here is the log window:
Please click on the {i} icon and paste your log as text into that window, this maintains the spacing and formatting in the log and makes it easier for us to view and understand.
The "I" icon where and paste it into what window?
It's in the icon bar when you type your message, sixth from the left.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 data norm4 (y=intercept+slope*x); _ 22 ERROR 22-7: Invalid option name Y. 74 call streaminit(0); 75 do i=1 To 20; 76 x= rand("uniform"); 77 do intercept=5 TO 10; 78 do slope=10 To 20; 79 output; 80 end; 81 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 82 83 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 95
So you have some basic programming errors here.
You can't put programming or mathematics in DATA statement itself.
The formula to compute Y has to go after x, intercept and slope are mentioned, otherwise the formula can't be evaluated.
Paige,
I am not sure how to mention x, intercept and slope.
Do I have to use the proc reg function first?
@fanellm1 wrote:
Paige,
I am not sure how to mention x, intercept and slope.
but your code did mention x intercept and slope.
Do I have to use the proc reg function first?
No you are not computing a regression here.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.