PROC PHREG;
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.
RUN;
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?
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; %end; &result. %mend; /* 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.
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?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.