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

Hi,

 

new to SAS.

 

I need to make a line graph. 

1. x-axis are dates (daily levels),

2. y-axis are cumulative frequency of subjects starting at 0 and with a maximum value of 400.

3. add a reference line (red dash-line). starts from "0" (y-axis) and the first date (variable="enrldt",x-axis) up to the fixed value of "400" in 14days (see "want" example below).

 

current output (not sure why there's 2 reference line in red. Want "subects" to start from 0):

HitmonTran_1-1610927668019.png

 

 

want (reference line up to 400 within 14day time frame from the first date (variable="enrldt"):

HitmonTran_0-1610926925028.png

 

data (example data below will not match to data in graph):

usubjid   enrldt
bob        01-01-2021
alex       01-01-2021
sara       02-02-2021
chris      03-02-2021
patty      04-03-2021
jon        05-01-2021
dav        06-02-2021
justin     07-02-2021
cara       08-03-2021

 

 

current code (not outputting the way I want it to):

proc sort data=adam.adsl out=adsl(keep=usubjid subjid enrlfl enrldt trt: age siteid);
	by usubjid enrldt;
	where enrlfl='Y';
run;
 
proc summary data = adsl nway;
   class enrlfl enrldt;
   format enrldt monyy7.;
   output out=work.summary (drop=_type_);
run;

/* cumulative freq count*/
data work.toplot;
   set work.summary;
   by enrlfl enrldt;
   retain count;
   if first.enrlfl then count=_freq_;
   else count+_freq_;
   enrldt = intnx('month',enrldt,0,'B');
run;

/**graph**/
Proc sgplot data=work.toplot;
   lineparm x=enrldt y=1 slope=%eval(400/14)/ lineattrs=(pattern=mediumdash color=red thickness=1) transparency=0.4; 
   yaxis Values=(0 to 400 by 100) ;
   
  XAXIS DISPLAY=(enrldt);
  YAXIS DISPLAY=(Cumulative Freq);
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
tarheel13
Rhodochrosite | Level 12

@ballardw is right. You have to store the first enrollment date instead of putting x=enrldt in lineparm. If you do that, you won't get 2 ref lines anymore. You could get first enrollment date using min in PROC SQL.


data enroll;
input usubjid $ enrldt :ddmmyy10.;
format enrldt yymmddd10.;
datalines;
bob 01-01-2021
alex 01-01-2021
sara 02-02-2021
chris 03-02-2021
patty 04-03-2021
jon 05-01-2021
dav 06-02-2021
justin 07-02-2021
cara 08-03-2021
;
run;

data enroll;
set enroll;
enrlfl='Y';
run;

proc sort data=enroll out=enroll_sorted;
by usubjid enrldt;
run;

proc summary data = enroll nway;
class enrlfl enrldt;
format enrldt monyy7.;
output out=work.summary (drop=_type_);
run;

/* cumulative freq count*/
data work.toplot;
set work.summary;
by enrlfl enrldt;
retain count;
if first.enrlfl then count=_freq_;
else count+_freq_;
enrldt = intnx('month',enrldt,0,'B');
run;

proc sql noprint;
select min(enrldt) into :first_enrollment
from enroll;
quit;

%put &=first_enrollment;

/**graph**/
Proc sgplot data=work.toplot;
lineparm x=&first_enrollment y=1 slope=%eval(400/14)/ lineattrs=(pattern=mediumdash color=red thickness=1) transparency=0.4;
yaxis Values=(0 to 400 by 100) ;
series x=enrldt y=count/ markers;
run;

 

lrackley_0-1610940249975.png

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Without data or the complete plot code there is no way to tell exactly why you are getting two reference lines.

 

I think that you may want to set a single value for X of the lineparm.

 

You do not show any attempt to determine the "earliest" enrldt. The manipulation of that variable in the data step is currently going to give you value for the start of each month that appears in your data. So you need to consider that in your summary. IF you want to have an actual x of enrldt for other bits of your plot then perhaps make a new variable, possibly only on the first value of enrlfl, with the desired value of x for the line parm.

HitmonTran
Pyrite | Level 9
i edited my post with sample data, thanks you ballardw.
tarheel13
Rhodochrosite | Level 12

@ballardw is right. You have to store the first enrollment date instead of putting x=enrldt in lineparm. If you do that, you won't get 2 ref lines anymore. You could get first enrollment date using min in PROC SQL.


data enroll;
input usubjid $ enrldt :ddmmyy10.;
format enrldt yymmddd10.;
datalines;
bob 01-01-2021
alex 01-01-2021
sara 02-02-2021
chris 03-02-2021
patty 04-03-2021
jon 05-01-2021
dav 06-02-2021
justin 07-02-2021
cara 08-03-2021
;
run;

data enroll;
set enroll;
enrlfl='Y';
run;

proc sort data=enroll out=enroll_sorted;
by usubjid enrldt;
run;

proc summary data = enroll nway;
class enrlfl enrldt;
format enrldt monyy7.;
output out=work.summary (drop=_type_);
run;

/* cumulative freq count*/
data work.toplot;
set work.summary;
by enrlfl enrldt;
retain count;
if first.enrlfl then count=_freq_;
else count+_freq_;
enrldt = intnx('month',enrldt,0,'B');
run;

proc sql noprint;
select min(enrldt) into :first_enrollment
from enroll;
quit;

%put &=first_enrollment;

/**graph**/
Proc sgplot data=work.toplot;
lineparm x=&first_enrollment y=1 slope=%eval(400/14)/ lineattrs=(pattern=mediumdash color=red thickness=1) transparency=0.4;
yaxis Values=(0 to 400 by 100) ;
series x=enrldt y=count/ markers;
run;

 

lrackley_0-1610940249975.png

 

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
  • 3 replies
  • 1304 views
  • 1 like
  • 3 in conversation