BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7
I have two categorical variable of 4 levels each and a continuous variable.  Is there a way to save schoenfeld's residuals for all the variables?  The way I know is to provide the residual variable names in the OUTPUT statement and SAS outputs the residuals in the order of the variables that come in the "Analysis of Maximum Likelihood Estimates' table. for eg. 
CLASS race sex;
MODEL time*censor(0)=race sex age;
OUTPUT OUT=outres RESSCHI=reswhite resblack resAsian resfemale resage; **these variables come in this order
in the Analysis of MLE table.
I have to run multiple models with different comorbidities and I am wondering if there is a way to request SAS to output the residuals for all the variables in the model without having to write them out in OUTPUT statement..

Accepted Solutions
Jade | Level 19

Hello @PamG,


Have you tried the RESSCH=_ALL_ option of the OUTPUT statement or are you not satisfied with the default variable names RESSCH_... created by this option?

View solution in original post

Super User

I am not sure exactly what your need is.

Are you looking for a way to create matching list of residual variable names? Such as provide the list of variables on the model and create the matching variable names for the output statement?


As far as I know Proc Phreg will only use one model statement and output statement per procedure call so I'm not sure where the "all variables" come into the request. The names are actually irrelevant. you can use an output statement like

   output out=work.phregout ressch=v1-v100;

which would name the residual variables v1 through v100 if there are 100 variables in the model. If there are only 5 variables in the model only v1 through v5 are created. But with different variables on the model V1 from one model doesn't represent the residuals of the same variable if the first variable in the model statement differs.


This a macro that allows you to place a prefix in front of each of a space delimited words, default is res_ provide a different string as prefix=oth as desired. This will create a matching list simpler.

%macro res(vlist,prefix=res_);
   %let result=;
   %do i=1 %to %sysfunc(countw(&vlist));
      %let word= %scan(&vlist,&i);
      %let result= &result &prefix.&word;
/* example to show what the result looks like in the log*/
%put %res( one two three);

Use would look like this

model <whatever> = one two three /other options;
output out=outset ressch= %res( one two three) <other options>;

Caveats: If your variable names are long the resulting variable names can get truncated with unexpected results.

If you have name literals "this is a literal"n for names this macro will not work at all.

Please note that the line of the macro before the %mend statement does not have a ; because it would become part of the value returned by the macro ending your output statement early. And likely to cause a number of errors therefrom.



Jade | Level 19

Hello @PamG,


Have you tried the RESSCH=_ALL_ option of the OUTPUT statement or are you not satisfied with the default variable names RESSCH_... created by this option?

Obsidian | Level 7
Thank you @FreelanceReinh. I did not know that was an option. It worked. Thanks!!!



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3 in conversation