Hello,
I would like to run a clustered log rank test. I used the following SAS macros from github: https://github.com/mstedman2/logrank-macro?tab=readme-ov-file but I'm getting erros when I run it on sample data in SAS studio. Could you help or guide me to a similar macros? Thanks in advance
Here is my code:
data samp_data;
do i = 1 to 1000;
/* Generate random time */
time_var = floor(rand('Uniform') * 730);
/* Generate random number between 0 and 1 */
rand_num = rand('Uniform');
/* Assign 1 if random number > 0.5, else assign 0 */
censor_var = (rand_num > 0.5);
/* Generate random group */
if rand_num > 0.6 then group_var="A";
else group_var="B";
/* Generate clusters */
x = rand('Uniform');
y = rand('Uniform');
/* Assign clusters based on conditions */
if i < 150 then cluster_var = 1;
else if i <450 then cluster_var = 2;
else cluster_var = 3;
output;
keep time_var cluster_var group_var censor_var;
end;
run;
%clusterlr (datain=samp_data, time=time_var, cluster=cluster_var, group=group_var, censor=censor_var);
quit;
Here is an example of errors:
Hello @Amine_Khemiri,
Have you tried running the macro with the sample data provided by the author (see program https://github.com/mstedman2/logrank-macro/blob/master/simsurvival.sas)? If that works (I can't test it myself as my SAS license does not include SAS/IML), I would compare the structure of the two input datasets.
Your dataset SAMP_DATA exhibits a very strong dependency between the group identifier and the censoring flag: Approximately 83 percent of the observations with group_var='B' are censored (censor_var=0), whereas censor_var=1 throughout group A. This is because you use the same random number to generate censor_var and group_var:
@Amine_Khemiri wrote:
/* Assign 1 if random number > 0.5, else assign 0 */
censor_var = (rand_num > 0.5);
/* Generate random group */
if rand_num > 0.6 then group_var="A";
else group_var="B";
I suspect that you actually wanted to generate group_var independently, for example with
if rand('Uniform') > 0.6 then group_var="A"; else group_var="B";
or equivalently (identical result) with
group_var=char('AB', rand('bern',0.6)+1);
Please, any time you discuss errors include the entire log of the step or procedure generating the error message. Copy the text, on the forum open a text box using the </> icon to preserve the formatting of text generated by SAS and include all the code with all the messages.
When having such a problem with a macro then set: Options Mprint;
before executing the macro (again) so the log will have more details of the generated code and text. Additionally Mprint will cause the error messages in the log to appear in better proximity to the problem statement.
Best would be to include the code of the Macro as well so it is available to all. For example, I am not able to access Github because of my organizations security protocols. Hopefully the macro will also include requirements of the data.
For example you have a variable called Time_var that if the value is treated by the macro as a SAS time value appears to have a range of just over 12 minutes. Is that expected by the macro?
Hello @Amine_Khemiri,
Have you tried running the macro with the sample data provided by the author (see program https://github.com/mstedman2/logrank-macro/blob/master/simsurvival.sas)? If that works (I can't test it myself as my SAS license does not include SAS/IML), I would compare the structure of the two input datasets.
Your dataset SAMP_DATA exhibits a very strong dependency between the group identifier and the censoring flag: Approximately 83 percent of the observations with group_var='B' are censored (censor_var=0), whereas censor_var=1 throughout group A. This is because you use the same random number to generate censor_var and group_var:
@Amine_Khemiri wrote:
/* Assign 1 if random number > 0.5, else assign 0 */
censor_var = (rand_num > 0.5);
/* Generate random group */
if rand_num > 0.6 then group_var="A";
else group_var="B";
I suspect that you actually wanted to generate group_var independently, for example with
if rand('Uniform') > 0.6 then group_var="A"; else group_var="B";
or equivalently (identical result) with
group_var=char('AB', rand('bern',0.6)+1);
Thanks ! Indeed it works with the sample data provided by author and the issue was in my sample data which is not in the correct design.
Hello,
I have also tried this macro and I get a similar error. I can't include the entire log as it is so big it fills the output space.
It appears to be the same thing over and over again
The clusters in my study represent the eyes within a patient, with ID=cluster identifier.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: