BookmarkSubscribeRSS Feed
BharathBandi
Calcite | Level 5

I applied a set of rules to eliminate records using if then else. so now i want to calculate average of the selected ones for each rule. when im using proc meant for those rules it is giving me only the average of the eliminated ones but not selected ones.

it looks something like this

data abc;

     set xyz;

          if abc<9000 then rule1=1;

          else if xu=1 then rule2=1;

          else selected =1;

run;

thank you

11 REPLIES 11
Reeza
Super User

Show your proc means code.

BharathBandi
Calcite | Level 5

proc means data=abc mean;

  class Rule /mlf order=data;

  types rule;

  var score;

run;

LinusH
Tourmaline | Level 20

Been a while since I dug into PROC MEANS, but I can't see that you sample code makes sense.

Your data step produces rule1 and rule2 variables, but you refer to rule in means.

Without knowing what you try to achieve, perhaps selected could be rule = 3...? Or run means twice?

Data never sleeps
Reeza
Super User

If I understand your question, which I'm not sure I do, you're creating 3 groups and using 3 variables to do so.

Use one variable with three different levels instead and use that in your class statement.

data abc;

     set xyz;

          if abc<9000 then rule=1;

          else if xu=1 then rule=1;

          else rule =3;

run;

proc means data=abc mean;

  class Rule;

  var score;

run;

BharathBandi
Calcite | Level 5

Sorry my mistake this is how my proc means look like:

proc means data=exclusion_selected mean;

  Class rule1 rule2 selected/missing;

  types rule1 rule2 selected;

  var score;

run;

Reeza
Super User

Did you try the code I suggested?

Otherwise please provide sample input/output data for what your looking for. Your code is correct, syntax wise, so not sure why your not getting what you want (mostly because we don't know what you want).

BharathBandi
Calcite | Level 5

data abc;

     set xyz;

          if abc<9000 then rule1=1;

          else if xu=1 then rule2=1;

          else if age <18 then rule3=1;

          else if age >65 then rule4=1;

          else selected =1;

run;

now i need to calculate Average of the Score. For example:

Data rule1;

     Set   abc;

          if  rule1=1 then delete;

     run;

proc means data=rule1 mean maxdec=2;

     var score;

run;


data rule2;

     set rule1;

         if rule2=1 then delete;

run;

proc means data=rule2 mean maxdec=2;

     var score;

run;


Since I have 35 rules, I want to know alternative way to calculate the average of only selected observation of that particular rule.


Thank you.


Reeza
Super User

Use 1 variable with 35 levels instead.

BharathBandi
Calcite | Level 5

No, that wont work . For example lets say I have population of 100,000 and when applied rule1 it eliminates about 25,000,   Now I need to calculate average of 75,000 and apply rule2 on the selected ones (remaining 75,000)  if it eliminates about 10,000 then I need to calculate average of remaining 65,000 and so on.

In your case it will calculate average for the ones which are eliminated.  

Reeza
Super User

Ok, then I guess I don't understand. Good luck!

EDIT:

Initialize your rule variables to 0/1 rather than 1/missing.

You can use an array statement to do this:

array rule(36) rule1-rule35 selected {36*0};

Then try your proc means again.  You can probably use a WAYS 1 rather than list everything in your TYPES statement.

J_Madamba
SAS Employee

Assuming you use one(1) variable with 35 levels.

for example,

data abc;

     set xyz;

          if abc<9000 then rule=1;

          else if xu=1 then rule=2;

          ....(and so on).......

          else rule =35;

run;

You can use the WHERE option to eliminate every level.

Proc means data = abc (where = (rule GT 1)) mean maxdec = 2;

var score;

run;

Proc means data = abc (where = (rule GT 2)) mean maxdec = 2;

var score;

run;

and so on

Unfortunately, you'll have 35 proc means.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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