BookmarkSubscribeRSS Feed
BenBrady
Obsidian | Level 7

I have a data set that contains the variables "eligibility" and "predicted eligibility". These variables are assigned values 1 and 0. I wish to find the percentage of the times that the two variables match (i.e eligibility=0 and predicted eligibility=0 + eligibility=1 and predicted eligibility=1 all divided by the total)-this is to be called the match rate. The eligibility variable always remains the same, however the predicted eligibility variable depends on a probablity (called prob) that is used in assigning the predicted eligibility as being either 0 (if found_predict>=prob) or 1 (if found_predict<prob), where found_predict is a constant variable. I want to set up an array in a do loop that finds the matching rate for each probability. That is, i want code that looks at values for prob between 0.3 and 0.6 say (in increments of 0.01) and determines the match rate for each.

5 REPLIES 5
Kurt_Bremser
Super User

When you posted your question, right below the message window you could see this:

 

Stop right there! Before pressing POST, tick off this checklist. Does your post …

✔ Have a descriptive subject line, i.e., How do I ‘XYZ’? ✔ Use simple language and provide context? Definitely mention what version you’re on. ✔ Include code and example data? Consider using the SAS Syntax feature.

 

 

 

 

 

Please respect #3.

A macro that converts a SAS dataset into datastep code for posting can be found here.

ChrisNZ
Tourmaline | Level 20

@Kurt_Bremser

Nice. This information should automatically come to posters' attention.

 

@ChrisHemedinger

Is there a way to make Kurt's recommendations appear whenever someone opens a new thread and is seeking programing help, like a check list that users confirm they have taken into account before they can click "Post"?

ChrisHemedinger
Community Manager
We're looking at a way to make this more obvious for new users. Stay tuned.
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Astounding
PROC Star

It is a bit confusing to figure out what you are trying to do.  It is conceivable that arrays are a good tool for the job, or an irrelevant tool for the job.  At any rate, here are a couple of pieces of the puzzle.  To create your flag indicating whether actual eligibility matches predicted:

 

data want;

set have;

match = (eligibility = predicted_eligibility);

run;

 

To get its average value across observations (many ways to do this):

 

proc summary data=want;

   var match;

   output out=stats (keep=match_rate) mean=match_rate;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 3333 views
  • 8 likes
  • 5 in conversation