BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

Below is a section of my macro for creating a Kaplan-Meier curve with at-risk counts under the x-axis.  I used to have this work just fine, but now it consistently puts the first two columns where they sould be but then moves all others up one row.  Can anyone see in my code what was wrong?  I would assume that the error lies in the 10th lines of the code below.  The curve can be found in the attached file, and you can assume that &atrisk.=Y.

title; footnote;

%do i=1 %to &cols.;

      /* Prepare horizontal axis to display at-risk counts */

      %if &atrisk.=Y %then %do;

            %let tickstat=;

            %do j=0 %to &nticks.;

                  %let tickval=%eval(&j.*5);

                  %let trtval=%scan(&&risk_a&i.,%eval(&j+1),'|');

                  %let cntrlval=%scan(&&risk_b&i.,%eval(&j+1),'|');

                  %let tickstat=&tickstat. tick=%eval(&j.+1) "&tickval." j=l ' ' ' ' j=c "&trtval." j=c "&cntrlval.";

            %end;

            %put &tickstat.;

            axis1 order=(0 to &xaxis. by 5) minor=(number=4) label=(height=1.25 "&timeaxis. from Randomzation") value=(height=1 &tickstat.);

      %end;

            %else %do;

                  axis1 order=(0 to &xaxis. by 5) minor=(number=4) label=(height=1.25 "&timeaxis. from Randomzation") value=(height=1);

            %end;

      proc sort data=sdfdata&i.;

            by stratum descending survival;

      run;

      %let risklab1=%sysfunc(substr(&stratlab1.,1,8));

      %let risklab2=%sysfunc(substr(&stratlab2.,1,8));

      title1 h=1.5 justify=center "Kaplan-Meier &main. Curves - &&grouplab&i.";

      title2 h=1.25 justify=center "(&pop. Population)";

      proc gplot data=sdfdata&i.;

            note height=1 j=left font=swissl

                  %if &atrisk.=Y %then %do;

                        move=(0,6) "Patients at Risk"

                        move=(0,4.7) "&risklab1."

                        move=(0,3.3) "&risklab2."

                  %end;

        ;

            plot survrate1*survtime survrate2*survtime censvalue*survtime / overlay haxis=axis1 vaxis=axis2 legend=legend1;

            symbol1 i=stepj l=20 color=black;

            symbol2 i=stepj l=1 color=black;

            symbol3 i=none v=plus color=black;

      run;

      quit;

%end;

This may seem cumbersome, but here is the log output for the %put &tickstat.; statement:

tick=1 "0" j=l ' ' ' ' j=c "14" j=c "22" tick=2 "5" j=l ' ' ' ' j=c "13" j=c "19" tick=3 "10" j=l ' ' ' ' j=c "8" j=c "6"

tick=4 "15" j=l ' ' ' ' j=c "8" j=c "4" tick=5 "20" j=l ' ' ' ' j=c "2" j=c "1" tick=6 "25" j=l ' ' ' ' j=c "1" j=c "1" tick=7

"30" j=l ' ' ' ' j=c "1" j=c "1" tick=8 "35" j=l ' ' ' ' j=c "1" j=c "" tick=9 "40" j=l ' ' ' ' j=c "1" j=c "" tick=10 "45"

j=l ' ' ' ' j=c "1" j=c "" tick=11 "50" j=l ' ' ' ' j=c "1" j=c "" tick=12 "55" j=l ' ' ' ' j=c "1" j=c "" tick=13 "60" j=l '

' ' ' j=c "1" j=c "" tick=14 "65" j=l ' ' ' ' j=c "" j=c ""


KMcurve_AtRisk_off.png
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I know that it shouldn't make a difference but have you tried j=l ' ' j=l ' ' instead of the j=l ' ' ' '  ? I've had a few cases in other places such as legends where I had to get more explicit to create the vertical breaks I wanted.

View solution in original post

7 REPLIES 7
Cynthia_sas
SAS Super FREQ

Hi:

  Generally, with a statement like "I used to have this work just fine, but now it <works incorrectly>", my response is to recommend...call Tech Support. Especially if it worked just fine in 9.1.3 and you just changed to 9.2 or it worked fine in 9.2 and you just switched to 9.3 -- there were changes between those versions that could possibly cause differences, even if your code does not change. And also possible, if you said you wanted HTML or PDF output and you noticed changes, that's also a reason to work with Tech Support.

cynthia

djbateman
Lapis Lazuli | Level 10

I may have to go to tech support.  I have not changed versions of SAS (always used SAS 9.1.3), and I always output in RTF.  I have ran several different scenarios and it outputs correctly occasionally.  Not sure what is happening.  But thank you for your response.

ballardw
Super User

I know that it shouldn't make a difference but have you tried j=l ' ' j=l ' ' instead of the j=l ' ' ' '  ? I've had a few cases in other places such as legends where I had to get more explicit to create the vertical breaks I wanted.

djbateman
Lapis Lazuli | Level 10

This did the trick on each of my scenarios!  How annoying!  Such a simple fix.

Can you explain to me the difference between j=l ' ' j=l ' ' and j=l ' ' ' '?  What is the difference?  What is each condition doing?

ballardw
Super User

My reasoning, which may not be exactly correct is the j=l ' ' ' ' sets the justification for the first string and then lets defaults handle the second. Depending on length of strings, space used by  the proc, axis length and such it then sometimes works as desired (the frustrating part when it doesn't). The j=l ' ' j=l ' ' forces each string to be left justified (or center or right) on a new line.

djbateman
Lapis Lazuli | Level 10

I noticed that there was a scenario where the program was working properly, but when I made your suggested adjustment the labels got mixed up (the spaces were still there, but the "Patients at Risk" labels got shifted down).  I guess I should leave both lines in the macro and manually comment/uncomment the needed lines on the rare occasions that it doesn't produce the desired output.

Thank you for your help.

ballardw
Super User

It may be better, assuming the results show sufficient detail, to move the origin to the right so that the text has more room in the margin.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1024 views
  • 0 likes
  • 3 in conversation