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

Hello SAS users,

 

I'm running the following code:

 

data t0;
input Estimate Numord;
datalines;

2447 1
42 2
10 3
-39 4
-84 5
;
run;


data t2;
input beta_3;
datalines;

19
42
10
-42
-76
;
run;

proc sql;
  select count(a.beta_3<=b.Estimate)/count(a.beta_3) into :z0bar
  from t2 a,
  t0 b
  where b.numord=3
  ;
run;

%put _all_;

I am expecting 0.4 for z0bar, but I am getting 1. Why?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

 select sum(a.beta_3<=b.Estimate)/count(a.beta_3) into :z0bar

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What is it your trying to achieve?  The reason is, if you look at a table version of your data:

proc sql;
  create table tmp as
  select a.beta_3,b.estimate,a.beta_3<=b.Estimate as test,count(a.beta_3<=b.Estimate)/count(a.beta_3) as a format=best.
  from t2 a,
  t0 b
  where b.numord=3
  ;
run;

You will see that there is 5 rows with a 0 or 1 for each beta_3<=estimate, and the count(beta_3) will always be 1, as there is exactly 1 per row, 0/1=0 and 1/1=1, you get a 1 out.

GKati
Pyrite | Level 9

I'm trying to count the number of rows in b that are <= the value of the variable Estimate at numord=3, as a percentage of all the rows in b. 

 

Thx. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like (and this is verbose just to show working out):

  create table tmp as
  select a.*,
         b.tot,
         (select count(*) from t2 where beta_3 <= a.estimate) as sub,
         (calculated sub / b.tot) * 100  as percent
  from  (select * from t0 where numord=3) a
  left join (select count(*) as tot from t2) b
  on    1=1;
run;
Ksharp
Super User

 select sum(a.beta_3<=b.Estimate)/count(a.beta_3) into :z0bar

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 960 views
  • 0 likes
  • 3 in conversation