- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi new to SAS.
I am having difficulty deriving the:
1. y-axis (cumulative count of subjects) and
2.creating x-axis(months)
3. outputting it onto a .rtf file.
For the y-axis, i am currently using usubjid but it's outputting usubjid # and not # of subject. I think i have to get the cumulative counts and use it as my y-axis but not sure how to do so.
Thank you
want:
my data:
usubjid enrldt
bob 01-01-2021
alex 01-01-2021
sara 02-02-2021
chris 03-02-2021
patty 04-03-2021jon 05-01-2021
dav 06-02-2021
justin 07-02-2021
cara 08-03-2021
my code:
proc sort data=adam.adsl out=adsl(keep=usubjid enrlfl enrldt);
by usubjid;
where enrlfl='Y';
run;
proc sgplot data=adsl noautolegend;
reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=enrldt y=usubjid;
yaxis grid;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@HitmonTran wrote:
sorry yes i meant "cumulative count of subjects" would the code above work? thank you
No because there is no accumulation. You would need to do an additional step to do so such as:
proc summary data = adam.adsl nway; class enrlfl enrldt; format enrldt monyy7.; output out=work.summary (drop=_type_); run; /* accumlate 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'); end; Proc sgplot data=work.toplot; where enrlfl="whatever"; reg x=enrldt y=count / lineattrs=(pattern=shortdash); series x=enrldt y=count; yaxis grid; label count='Cumulative count'; run;
The INTNX function in the data step adjusts actual dates so they all represent the first of the month which might make your graph a bit closer to your expectations.
Here you see why I used the Enrlfl variable in the summary. You can select just to plot for that data.
Or you could try
Proc sgplot data=work.toplot; reg x=enrldt y=count / lineattrs=(pattern=shortdash); series x=enrldt y=count / group=enrlfl; yaxis grid; label count='Cumulative count'; run;
to superimpose the different enrlfl values on one graph.
Or use Enrlfl on a BY statement to create one graph per level.
Or use Proc SGpanel with Enrlfl as the Panelby variable which can make panels of graphs, one for each level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you want the yaxis to be "count of subjects per date" or some sort of "cumulative count of subjects" as the text in that image shows?
If the cumulative then a regression line doesn't really make much sense because regression should mean that the result for each date is independent of other dates, which would not be the case in cumulative totals.
You need to do something to create the count per date to do series, scatter and similar graphs. The bar graphs, like VBAR or HBAR can to a count per date but aren't going to be series.
proc summary data = adam.adsl nway; class enrlfl enrldt; output out=work.toplot (drop=_type_); run; /* toplot will have enrlfl and enrldt plus a variable _freq_ that counts how many records for each combination of enrlfl and enrldt */ Proc sgplot data=work.toplot; reg x=enrldt y=_freq_ / lineattrs=(pattern=shortdash); series x=enrldt y=_freq_; yaxis grid; label _freq_='Subject count'; run;
You do not show very much "data" so I can't tell if you actually want count be date or per month as per your example image. If you need per calendar month (or other typical period) you can use a format to create summaries by the formatted value of Enrldt if that variable is an actual date value. A format of MONYY7. applied in proc summary to a date variable creates groups like MAY2020.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@HitmonTran wrote:
sorry yes i meant "cumulative count of subjects" would the code above work? thank you
No because there is no accumulation. You would need to do an additional step to do so such as:
proc summary data = adam.adsl nway; class enrlfl enrldt; format enrldt monyy7.; output out=work.summary (drop=_type_); run; /* accumlate 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'); end; Proc sgplot data=work.toplot; where enrlfl="whatever"; reg x=enrldt y=count / lineattrs=(pattern=shortdash); series x=enrldt y=count; yaxis grid; label count='Cumulative count'; run;
The INTNX function in the data step adjusts actual dates so they all represent the first of the month which might make your graph a bit closer to your expectations.
Here you see why I used the Enrlfl variable in the summary. You can select just to plot for that data.
Or you could try
Proc sgplot data=work.toplot; reg x=enrldt y=count / lineattrs=(pattern=shortdash); series x=enrldt y=count / group=enrlfl; yaxis grid; label count='Cumulative count'; run;
to superimpose the different enrlfl values on one graph.
Or use Enrlfl on a BY statement to create one graph per level.
Or use Proc SGpanel with Enrlfl as the Panelby variable which can make panels of graphs, one for each level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Proc sgplot data=work.toplot;
where enrlfl='Y';
reg x=enrldt y=count / lineattrs=(pattern=shortdash);
series x=enrldt y=count;
yaxis grid;
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
label count='Cumulative count';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
please try the below approach
proc sort data=adam.adsl out=adsl(keep=usubjid enrlfl enrldt);
by enrldt;
where enrlfl='Y';
run;
data adsl;
set adsl;
retain count;
by enrldt;
if first.enrldt then count=1;
else count+1;
run;
ods rtf file='~path\line.rtf';
proc sgplot data=adsl noautolegend;
*reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=enrldt y=count;
yaxis grid;
run;
ods rtf close;
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
please try the below code
proc sort data=adam.adsl out=adsl(keep=usubjid enrlfl enrldt);
by enrldt;
where enrlfl='Y';
run;
proc format;
value mon
1='Jan'
2='Feb'
3='Mar'
4='Apr'
5='May'
6='Jun'
7='Jul'
8='Aug'
9='Sep'
10='Oct'
11='Nov'
12='Dec';
run;
data adsl;
set adsl;
month=month(enrldt);
run;
proc sort data=adsl;
by month;
run;
data adsl;
set adsl;
retain count;
by month;
if first.month then count=1;
else count+1;
run;
ods rtf file='F:\abgen\line.rtf';
proc sgplot data=adsl noautolegend;
*reg x=enrldt y=usubjid / lineattrs=(pattern=shortdash);
series x=month y=count;
yaxis grid;
XAXIS TYPE = DISCRETE GRID;
format month mon.;
run;
ods rtf close;
Jag