BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raja777pharma
Fluorite | Level 6

Hello,

 

I have defeind the refline for specific date but it was coming before the date rather than specified.

Below is my output, the refline date is 11MAR2020 , but it was displaye before Mar2020.

raja777pharma_0-1641432632688.png

 

Below  is my code.

 

data prefinal;
  set indata;
   if fasfl='Y';
   cutoff=cov19pdt;    
   adt = FUPEDT;
      
   if randdt > cutoff then do;
     adt2=adt;
     randdt2=randdt;
     before='Y';
   end;
   else if adt < cutoff then do;
     adt1=adt;
     randdt1=randdt;
     after='Y';
   end;
   else do;
     randdt1=randdt;
     adt1=cutoff;
     randdt2=cutoff;
     adt2=adt;
     both='Y';
   end;   
   format  randdt randdt1 adt randdt2 adt2 cutoff date9. ;        
   keep usubjid randdt1 adt1 randdt2 adt2 cutoff randdt adt fupedt;
run;

proc sql noprint ;
  create table xaxisdt as
  select min(randdt) as xstdt format date9.
        ,max(adt) as xendt format date9.
        ,max(cutoff) as cutoffdt format date9.
  from prefinal;
quit;

data xaxisdt;
  set xaxisdt;
  stdtn=intnx('month',xstdt,-1,'s');
  stdtc=put(stdtn,date9.);  
  endtn=intnx('month',xendt,1,'s');
  endtc=put(endtn,date9.);
  
  keep stdtc endtc cutoffdt;
run;

proc sql noprint;
  select stdtc,endtc ,cutoffdt into: xstdt, :xendt, :cutoffdt
  from xaxisdt;
quit;

proc sgplot data=final;
       highlow Y=N low=RANDDT1 high=ADT1/lineattrs=(thickness=1.5 pattern=solid color=grey) name='C' legendlabel='Follow-up Days';
       highlow Y=N low=RANDDT2 high=ADT2/lineattrs=(thickness=1.5 pattern=solid color=charcoal) name='C' legendlabel='Follow-up Days';
       yaxis label="Subjects (N = %trim(&n99))"  values=(0 1000 2000 3000 4000 5000 6000 6500);
       xaxis label="Study Calendar" interval=quarter VALUESFORMAT=MONYY7.;
       refline "&cutoffdt."d/ axis=x  lineattrs=(thickness=3 pattern=dash color=black) label="&cutoffdt. (COVID-19 Pandemic Date)";
       
        inset "%trim(&nbe)% Of follow-up days prior to the start of COVID-19 pandemic" / position=left textattrs=(color=black  size=9);
        inset "%trim(&ndu)% Of follow-up days after or on the start of COVID-19 pandemic" / position=right textattrs=(color=black  size=9); 
run;

 

Also please let me know how we can wrap inset text.

 

Thank you,

Rajasekahar B

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Hi,

 

I think the problem is that your plot has a linear axis rather than a time axis.  To fix it, make sure randdt1 randdt2 addt1 addt2 all have date formats attached to them in work.final (you could add a format statement inside the SGPLOT).  This should trigger SGPLOT to use a time axis.

 

One warning sign in your picture is that the month names are not the start of a quarter (they should be Jan, Apr, Jul, Oct).  The easiest way to confirm this problem is to change the xaxis to valuesformat=date9.  It should show you that the day values for each month are not the first or the last of the month, because it's a linear axis I think the start point is driven by the data.  I'm surprised that SGPLOT doesn't throw at least a NOTE to say that you are using a time interval for a linear axis.  I thought you could fix this by adding type=time to the axis statement, but SAS then throws a note that although you have requested a time axis, the axis will be changed to linear because the values being plotted are not time values.

 

So in order to get a proper time axis, it looks like the values need to be formatted as dates (or date-times or times) so SGPLOT knows it is plotting time values.  Then SGPLOT will give you a time axis rather than a linear axis.

 

Sample code below.  It's always helpful to make a tiny test case when exploring SAS questions, so that you can narrow down the problem.

 

data have ;
  do randdt1="01Jan2020"d to "01Jan2021"d by 10 ;
    randdt2=randdt1+100 ;
    N++1 ;
    output ;
  end ;
run ;


title1 "This plot has a linear axis rather than a time axis because the variables are not formatted as dates" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=mmddyy10. ;
run ;
title1 ;

title1 "This plot has a time axis because randdt1 and randdt2 have a date format attached" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=mmddyy10. ;
  format randdt1 randdt2 date9. ;
run ;
title1 ;

title1 "This plot has a time axis because randdt1 and randdt2 have a date format attached" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=monyy7. ;
  format randdt1 randdt2 date9. ;
run ;
title1 ;

 

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Reeza
Super User
Show the value of the cutoff date macro variable.
raja777pharma
Fluorite | Level 6

cutoff maccro variable resolve to 11Mar2020 and date formate in data set is date9.

Thank you,
Rajasekhar Reddy.

LalitPatel
Obsidian | Level 7

Mar2020 tick-mark on X axis corresponds to 31Mar2020.

 

raja777pharma
Fluorite | Level 6
How we can create tick values for starting of the month, i,e 01Mar2020
Ksharp
Super User
If you want "wrap inset text." ,try multiple quote for INSET.

proc sgplot data=sashelp.class;
scatter x=weight y=height/datalabel=name group=sex;
inset "%trim(&nbe)% Of follow-up days" "prior to the start of COVID-19 pandemic" / position=left textattrs=(color=black size=9);
inset "%trim(&ndu)% Of follow-up days" "after or on the start of COVID-19 pandemic" / position=right textattrs=(color=black size=9);
run;
Quentin
Super User

Hi,

 

I think the problem is that your plot has a linear axis rather than a time axis.  To fix it, make sure randdt1 randdt2 addt1 addt2 all have date formats attached to them in work.final (you could add a format statement inside the SGPLOT).  This should trigger SGPLOT to use a time axis.

 

One warning sign in your picture is that the month names are not the start of a quarter (they should be Jan, Apr, Jul, Oct).  The easiest way to confirm this problem is to change the xaxis to valuesformat=date9.  It should show you that the day values for each month are not the first or the last of the month, because it's a linear axis I think the start point is driven by the data.  I'm surprised that SGPLOT doesn't throw at least a NOTE to say that you are using a time interval for a linear axis.  I thought you could fix this by adding type=time to the axis statement, but SAS then throws a note that although you have requested a time axis, the axis will be changed to linear because the values being plotted are not time values.

 

So in order to get a proper time axis, it looks like the values need to be formatted as dates (or date-times or times) so SGPLOT knows it is plotting time values.  Then SGPLOT will give you a time axis rather than a linear axis.

 

Sample code below.  It's always helpful to make a tiny test case when exploring SAS questions, so that you can narrow down the problem.

 

data have ;
  do randdt1="01Jan2020"d to "01Jan2021"d by 10 ;
    randdt2=randdt1+100 ;
    N++1 ;
    output ;
  end ;
run ;


title1 "This plot has a linear axis rather than a time axis because the variables are not formatted as dates" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=mmddyy10. ;
run ;
title1 ;

title1 "This plot has a time axis because randdt1 and randdt2 have a date format attached" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=mmddyy10. ;
  format randdt1 randdt2 date9. ;
run ;
title1 ;

title1 "This plot has a time axis because randdt1 and randdt2 have a date format attached" ;
proc sgplot data=have ;
  highlow y=N low=randdt1 high=randdt2;
  refline "11Mar2020"d /axis=x ;
  xaxis interval=quarter  valuesformat=monyy7. ;
  format randdt1 randdt2 date9. ;
run ;
title1 ;

 

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 595 views
  • 1 like
  • 5 in conversation