BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Amine_Khemiri
Obsidian | Level 7

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:

Amine_Khemiri_0-1710972300834.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

 

View solution in original post

3 REPLIES 3
ballardw
Super User

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?

FreelanceReinh
Jade | Level 19

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

 

Amine_Khemiri
Obsidian | Level 7

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 265 views
  • 0 likes
  • 3 in conversation