BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
valarievil
Obsidian | Level 7

I have a large set of random uniform distributed numbers between -6 and 10. My goal is to find the probability that the mean of my sample is between 2 and 3.  I used the advice from a related post (https://communities.sas.com/t5/General-SAS-Programming/Random-numbers-Sample-size-then-calculate-mea...)

 

But I am still getting an error, Here is the code I am attempting:

 

data Prob1A;
call streaminit (0);
k= 2000;
n= 40000;
do i=1 to k;
	xuni= rand('uniform', -6, 10);
	output;
keep xuni; 
end;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=1Ameans mean=SampleMean std=SampleStd;
run;
data p23;
set 1Ameans;
A1sol = (2< SampleMean < 3);
run;
proc freq data= p23;
tables A1sol;
run;

I'm not getting any output except for the error message: ERROR: Variable A1SOL not found. Why does my program not recognize this variable A1SOL? I thought it was adequately defined. Also I'm a bit stuck on how to proceed from here. I would like to be able to print the probability that the sample means are between 2 and 3. Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
valarievil
Obsidian | Level 7

Thanks for everyone's responses! After accumulating your collective advice, I have come up with a code that gives me what I need:

 

data Prob1A;
call streaminit (47);
k= 2000;
n= 40000;
do sampleid=1 to k;
 do j=1 to n;
	xuni= rand('uniform', -6, 10);
	output;
 end;
end;
keep sampleid xuni; 
run;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=A1means mean=SampleMean std=SampleStd;
run;
data p197_24;
set A1means;
A1sol = (1.97< SampleMean < 2.4);
run;
proc freq data= p197_24;
tables A1sol;
run;

Thanks again!

 

Sorry the parameters are different than the original question.

View solution in original post

14 REPLIES 14
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

because you proc means fails.

this by SampleID;

 

you have to have the by variable in the dataset being evaluated.

 

valarievil
Obsidian | Level 7

What should I use instead of sampleID?

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

@valarievil you can use SampleID you just have to have it in the SAS dataset.  So your first error in the process was at your proc means because the incoming dataset did not have SampleID in it.  

PaigeMiller
Diamond | Level 26

@valarievil wrote:

I have a large set of random uniform distributed numbers between -6 and 10. My goal is to find the probability that the mean of my sample is between 2 and 3.  I used the advice from a related post (https://communities.sas.com/t5/General-SAS-Programming/Random-numbers-Sample-size-then-calculate-mea...)

 

But I am still getting an error, Here is the code I am attempting:

 

data Prob1A;
call streaminit (0);
k= 2000;
n= 40000;
do i=1 to k;
	xuni= rand('uniform', -6, 10);
	output;
keep xuni; 
end;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=1Ameans mean=SampleMean std=SampleStd;
run;
data p23;
set 1Ameans;
A1sol = (2< SampleMean < 3);
run;
proc freq data= p23;
tables A1sol;
run;

I'm not getting any output except for the error message: ERROR: Variable A1SOL not found. Why does my program not recognize this variable A1SOL? I thought it was adequately defined. Also I'm a bit stuck on how to proceed from here. I would like to be able to print the probability that the sample means are between 2 and 3. Thanks in advance!


Surely there must be an earlier error in the LOG. Your PROC MEANS must have an error as well.

--
Paige Miller
valarievil
Obsidian | Level 7
But why is the variable A1sol not defined?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Please slow down.

you need to get a SampleID variable in this process before you can continue.

 

proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out
=1Ameans mean=SampleMean std=SampleStd;
run;

data Prob1A;
call
streaminit (0);
k
= 2000;
n= 40000;
do i
=1 to k;
xuni
= rand('uniform', -6, 10);
output
;
keep xuni;
end
;

 

 

Where is the SampleID that proc means is doing the by on in Prob1A????

 

 

data Prob1A;
retain SampleID 0;
call streaminit (0);
k= 200;
n= 4000;
do b = 1 to 10;
do i=1 to k;
 SampleID =b +1;
 xuni= rand('uniform', -6, 10);
 output;
keep xuni SampleID;
end;
end;
run;

valarievil
Obsidian | Level 7
I keep getting the error "variable A1SOL not found". Why?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

you have a sas dataset that has a 1 at the begging.

remove the 1 from 1Ameans because that dataset is really Ameans when created by SAS

 

data p23;
set 1Ameans; A1sol = (2< SampleMean < 3);
run;
proc freq data= p23;
tables A1sol;
run;

valarievil
Obsidian | Level 7

Will somebody please tell me why I keep getting the error "variable A1SOL not found"? What did I do wrong?

PaigeMiller
Diamond | Level 26

People have told you what you did wrong. You have errors earlier in the program, as PROC MEANS cannot work. I believe @VDD has pointed them out.

--
Paige Miller
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

then you have an incorrect SAS dataset name

 

calling it 1A can not happen SAS droped the 1 when it created the dataset here

 

proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out
=1Ameans mean=SampleMean std=SampleStd;
run;

 

And you need to do a proc sort on the incoming dataset if you use the by statement.

Did you @valarievil need to call the class SampleID or the by SampleID statement here.

 

valarievil
Obsidian | Level 7
I tried that and I'm still not getting an output.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

please show complete log for ever datastep and proc somethings are issue prior to the final error.  Start at the begging.

.

valarievil
Obsidian | Level 7

Thanks for everyone's responses! After accumulating your collective advice, I have come up with a code that gives me what I need:

 

data Prob1A;
call streaminit (47);
k= 2000;
n= 40000;
do sampleid=1 to k;
 do j=1 to n;
	xuni= rand('uniform', -6, 10);
	output;
 end;
end;
keep sampleid xuni; 
run;
proc means data=Prob1A noprint;
by SampleID;
var xuni;
output out=A1means mean=SampleMean std=SampleStd;
run;
data p197_24;
set A1means;
A1sol = (1.97< SampleMean < 2.4);
run;
proc freq data= p197_24;
tables A1sol;
run;

Thanks again!

 

Sorry the parameters are different than the original question.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 1569 views
  • 0 likes
  • 3 in conversation