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 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:

HitmonTran_0-1609991704815.png

my data: 

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

 

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;



 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

 

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

HitmonTran
Pyrite | Level 9
sorry yes i meant "cumulative count of subjects" would the code above work? thank you
ballardw
Super User

@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.

 

HitmonTran
Pyrite | Level 9
Thanks! it worked but how do I remove the y-axis label without removed the gridlines and also remove the legend?


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;
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
HitmonTran
Pyrite | Level 9
i updated my post to update the x-axis as well (create months).
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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