Reputation: 13
I have case data of TB with the following variables: age, case_status, city, year, month, and race from the past 11 years (2006-2017). I would like to make a line graph of month by year with cases as the y axis, month as the x axis, and then a new line for each year. But I am unsure how to count the observations. I am new with sas so I apologize in advance if I am doing this wrong but this is what I had in mind:
PROC SORT DATA= TB
BY YEAR;
RUN;
DATA YEAR;
SET TB;
COUNT + 1;
BY YEAR;
IF FIRST.YEAR THEN COUNT =1;
RUN;
PROC SGPLOT DATA = YEAR;
SERIES X = Month Y = COUNT;
SERIES X = Year Y = COUNT;
TITLE 'Temporal Patterns of TB from 2006-2017';
RUN;
However I am getting a blank output with this code.
Any feedback/help would be greatly appreciated! Thank you in advance!
Upvotes: 1
Views: 542
Reputation: 27498
There are a variety of groupings, bys, or panelbys that might better communicate or better present the count variations of each year.
For example
data have (label="Disease cases");
do casedate = '01jan2006'd to '31dec2017'd;
year = year(casedate);
month = month(casedate);
do day_n = 1 to 30*ranuni(123);
case_status = floor(4*ranuni(123));
city_id = ceil(100*ranuni(123));
race = ceil(6*ranuni(123));
output;
end;
end;
run;
proc means noprint data=have;
class year month;
types year*month;
output out=counts n=freq;
run;
data counts;
set counts;
yearmo = mdy(month,1,year);
format yearmo yymmd7.;
run;
options orientation=landscape papersize=a4;
ods html close;
ods html;
proc sgplot data=counts;
series x=month y=freq / group=year;
xaxis type=discrete;
where _type_ = 3;
run;
proc sgplot data=counts;
series x=yearmo y=freq / group=year;
xaxis type=discrete display=(novalues);
where _type_ = 3;
run;
proc sgplot data=counts;
by year;
series x=yearmo y=freq / group=year;
xaxis type=discrete ;
where _type_ = 3;
run;
proc sgpanel data=counts;
panelby year;
series x=month y=freq ;
colaxis type=discrete;
where _type_ = 3;
run;
proc sgpanel data=counts;
panelby year / columns=4 ;
series x=month y=freq ;
colaxis type=discrete display=(novalues);
where _type_ = 3;
run;
Upvotes: 0
Reputation: 21264
This is much easier if you provide sample data. Assuming you're trying to do something similar to graphing a line chart, I'll use the SASHELP.PRDSALE data set as a demo. I use the weight statement here to add up the amounts but you won't need that.
First run PROC FREQ to get the summary statistics and then use the output from that in SGPLOT to get the graph. Your SG code is close.
proc freq data=sashelp.prdsale noprint;
table year*month / out=summary_stats;
weight actual;
run;
proc sgplot data=summary_stats;
series x=month y=count / group=year;
run;
Upvotes: 1