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;
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.
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.
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.