BookmarkSubscribeRSS Feed
fanellm1
Calcite | Level 5

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. Please
note 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;

 

proc reg;
model y=mx+b;
do m=10 To 20 b=5 To 10;
run;

15 REPLIES 15
PaigeMiller
Diamond | Level 26

@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. Please
note 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.

--
Paige Miller
fanellm1
Calcite | Level 5

Thanks Paige! 

 

Do I then need to define the slope and intercept somewhere?

PaigeMiller
Diamond | Level 26

Yes or no. Either. Depends on what you mean by "define". Give it a try.

--
Paige Miller
fanellm1
Calcite | Level 5

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: 

 

ERROR 12-63: Missing '=' for option KEEP.
 
ERROR 22-7: Invalid option name Y.
PaigeMiller
Diamond | Level 26

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 Miller
fanellm1
Calcite | Level 5

Paige, 

 

Here is the log window:

 

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data norm4 (keep y=intercept+slope*x);
____ _
12 12
22
ERROR 12-63: Missing '=' for option KEEP.
 
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
 
PaigeMiller
Diamond | Level 26

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 Miller
fanellm1
Calcite | Level 5

The "I" icon where and paste it into what window?

PaigeMiller
Diamond | Level 26

It's in the icon bar when you type your message, sixth from the left.

--
Paige Miller
fanellm1
Calcite | Level 5
 
 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         
PaigeMiller
Diamond | Level 26

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 Miller
fanellm1
Calcite | Level 5

Paige, 
I am not sure how to mention x, intercept and slope. 

fanellm1
Calcite | Level 5

Do I have to use the proc reg function first?

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 1373 views
  • 0 likes
  • 3 in conversation