SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jystat
Fluorite | Level 6

Hi,

 

I have a data set where one real outcome variable (binary variable 0 or 1) and the model predicted binary variable (0 or 1).

 

But I have 60 number of the model predicted binary variable in the data set, which means I need to create the 2*2 table with the actual outcome and each of the model predicted variable to compute the sensitivity, specificity, and youden's index.

 

Here is the screen shot of my data. In the below data set, allfrc is my real outcome variable and lnn_naa1, lnn_naa2,....., are my model predicted outcome.

 

lln.JPG

 

I used the following command to compute the sensitivity and sensitivity. 

 

proc sort data=mydata out=dataout;
by descending lnn_naa1 descending allfrc;
run;

proc freq data = dataout order=data;
table lnn_naa1*allfrc / senspec ;
test kappa;
run;

 

My questions are as below.

 

1) I created this as macro and run with each model predicted outcome variable (for example, lnn_naa1 * allfrc, and then lnn_naa2*allfrc). But this way takes a lot of time to run.

 

2) Any recommendation to run the actual outcome * model predicted outcome with calculating the sensitivity, specificity and youden's index?

 

Thank you for any help and comments!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You can use parentheses to group variables, or variable lists for use on a tables statement in proc freq.

 

Try

tables ( inn: )* allfrc / senspec;

 

Which should use all. of the variables whose names start with INN agains allfrc. If you need other variables

 

tables ( inn: )* (allfrc othervar somevar) / senspec;

would cross all of the inn vars against the three in parentheses.

View solution in original post

8 REPLIES 8
ChrisNZ
Tourmaline | Level 20

If you are going to run a proc freq many times on one table, try loading it in memory use SASFILE beforehand to speed up reading the data.

jystat
Fluorite | Level 6

Hi @ChrisNZ ,

 

Thank you for your comment.

 

I will try to look at the SASFILE to use in the memory. I'm kind of stuck that I need to sort first before I create the 2*2 table and then I do proc freq. 

 

I don't know how to make the out of sort file in the macro for each my model predicted outcome. Do you know how can I compute the sensitivty, specificity, and youden's index from proc freq table output? I have output of sensitivity and specificity from the table, not the youden's index.

 

Thank you.

 

 

 

ChrisNZ
Tourmaline | Level 20

Are you sure you need to sort? Sorting is normally needed only when using a BY statement.

jystat
Fluorite | Level 6

@ChrisNZ 

 

I do sorting always whenever I create the 2*2 table to look at the sensitivity and specificity. 

ballardw
Super User

You can use parentheses to group variables, or variable lists for use on a tables statement in proc freq.

 

Try

tables ( inn: )* allfrc / senspec;

 

Which should use all. of the variables whose names start with INN agains allfrc. If you need other variables

 

tables ( inn: )* (allfrc othervar somevar) / senspec;

would cross all of the inn vars against the three in parentheses.

jystat
Fluorite | Level 6

Hi @ballardw 

 

Thank you for your suggestion.

 

Yes, it is giving me all the frequency table with the (inn:). (I knew this techniques, but I never think about this, thank you for your response!)

 

I searched if there is anyway I can use to calculate the youden'x index from the output, but I do not see any SAS function. Do you know SAS has any this kind of function or I need to calculate by manually? 
 
Thank you!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3332 views
  • 6 likes
  • 3 in conversation