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):
want (reference line up to 400 within 14day time frame from the first date (variable="enrldt"):
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;
@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;
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.
@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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.