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.
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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;

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!

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