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

Hello guys,

 

I have 5 models 0, 1,2,3,4. My variables are  tool1, tool2, tool3, tool5, tool6, tool11, tool12 and AUC

 

data one;
input modelstep TOOL1 TOOL2 TOOL3 TOOL5 TOOL6 TOOL11 TOOL12 AUC 
datalines;
0 -0.097544 0.38682 -0.057215 0.19231 0.013377 -0.35196 0.58613 0.69676 
1 -0.097379 0.3858 -0.057377 0.19214 0.013363 -0.35187 0.58526 0.69668 
2 -0.096809 0.38621 -0.057295 0.19177 0.013297 -0.35061 0.58444 0.69618 
3 -0.09729 0.38838 -0.057003 0.19405 0.013242 -0.34783 0.57736 0.69666 
4 -0.096492 0.3881 -0.054853 0.19513 0.013091 -0.33446 0.57587 0.6963 
; run;

Data two;
set one;
retain difference_from_model0;
if first.AUC then difference_from_model0=0;
if last.id then output;
proc print; run;

i basically want to write a code to find the difference in AUC between model 0 and the other models (model 1 to model 4). Simply put , model 0- model1 will be first observation. model 0 - model 2 will be second observation. model 0 - model 3 will be third observation etc. 

I want my final output to be something like this

modelstep TOOL1 TOOL2 TOOL3 TOOL5 TOOL6 TOOL11 TOOL12 AUC Difference_from_model0

1 -0.097379 0.3858 -0.057377 0.19214 0.013363 -0.35187 0.58526 0.69668 xxxx
2 -0.096809 0.38621 -0.057295 0.19177 0.013297 -0.35061 0.58444 0.69618 yyyy
3 -0.09729 0.38838 -0.057003 0.19405 0.013242 -0.34783 0.57736 0.69666 zzzz
4 -0.096492 0.3881 -0.054853 0.19513 0.013091 -0.33446 0.57587 0.6963 cccc

 

I tried to use the retain function but have not been successful. My code is attached. Any help will be appreciated.

 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

It does not look like you have any BY groups in that data.  It is all one group with different values of MODELSTEP.

 

data want ;
  set one;
  retain AUC0;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;

If you have multiple models (each of which can have one or more steps) then you could use BY processing.

data want ;
  set one;
  by model;
  retain AUC0;
  if first.model then AUC0=.;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;

View solution in original post

3 REPLIES 3
ChuksManuel
Pyrite | Level 9

Here's a modification of my code. It's still not giving me any output that's meaningful. 

data two;
 set one;
  by outcome;
 retain difference_AUC_model0;
 if first.modelstep then difference_AUC_model0 = AUC;
 else difference_AUC_model0 = difference_AUC_model0 - AUC;
 run;  
proc print; run;
Tom
Super User Tom
Super User

It does not look like you have any BY groups in that data.  It is all one group with different values of MODELSTEP.

 

data want ;
  set one;
  retain AUC0;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;

If you have multiple models (each of which can have one or more steps) then you could use BY processing.

data want ;
  set one;
  by model;
  retain AUC0;
  if first.model then AUC0=.;
  if modelstep=0 then AUC0 = AUC ;
  diff = AUC - AUC0;
run;
ChuksManuel
Pyrite | Level 9

Thank you Tom.

 

Thank was indeed helpful

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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