Hi.
I have this example dataset (In my real dataset I have different 355 combinations)
Hi.
I have this example dataset (In my real dataset I have different 355 combinations)
Is the graph actually supposed to be "number tested that day" or a cumulative total or some sort of smoothing function applied to the counts? The graph you show does not appear to be a "daily count".
Is should basically be the number of tested - if thats possible?
This will do a connect the dot for the date and count plot with a series statement and drop line using needle to connect the value to the specific date when an even occurs:
data WORK.EXAMPLE;
infile datalines delimiter=',' truncover dsd;
input prdate :date9. events:$100. count ;
format prdate ddmmyy8.;
if not missing(events) then eventcount=count;
datalines4;
01Jan2020,., 0
27JAN2020,., 1050
28JAN2020,., 63721
29JAN2020,., 22812
30JAN2020,., 11121
01FEB2020,., 10511
02FEB2020,., 18180
11MAR2020,Lock down starts, 2345
15APR2020, Early reopening,12356
15AUG2020,Compulsory use of masks in public transport,46757
01SEP2020,Universities start, 34568
01OCT2020,., 3468
;;;;
ods graphics / width=10in height=10in;
proc sgplot data=work.example;
series x=prdate y=count;
needle x=prdate y=eventcount;
xaxis values=('01JAN2020'd to '01OCT2020'd by month)
label=
;
format prdate monname3.;
yaxis label='Count of Tests'
run;
The left part of the graph is ugly because you have sequential days with a wide range of values so the result is very jagged: not much time on the Xaxis and lots of variance on the Yaxis values.
This adds text oriented vertically but messes with the axis appearances and I don't have time to figure out all of the options that may need to be set to prevent that.
proc sgplot data=work.example;
series x=prdate y=count;
needle x=prdate y=eventcount;
xaxis values=('01JAN2020'd to '01OCT2020'd by month)
;
format prdate monname3.;
text x=prdate y=eventcount text=events
/rotate=90 position=right;
format prdate monname3.;
run;
You may want the NOAUTOLEGEND option on the Proc SGPLOT statement to suppress the legend since both automatic items are basically the same value displayed in different manner.
data WORK.EXAMPLE;
infile datalines delimiter=',' truncover dsd;
input prdate :date9. events:$100. count ;
_prdate=intnx('month',prdate,0);
format prdate _prdate ddmmyy8.;
if not missing(events) then eventcount=count;
events=cats(events,'|(',put(prdate,ddmmyy10.),')');
datalines4;
01Jan2020,., 0
27JAN2020,., 1050
28JAN2020,., 63721
29JAN2020,., 22812
30JAN2020,., 11121
01FEB2020,., 10511
02FEB2020,., 18180
11MAR2020,Lock down starts , 2345
15APR2020, Early reopening ,12356
15AUG2020,Compulsory use of masks in public transport ,46757
01SEP2020,Universities start , 34568
01OCT2020,., 3468
;;;;
ods graphics / noscale;
proc sgplot data=work.example noautolegend;
series x=_prdate y=count / smoothconnect;
xaxis valuesformat=monname3.;
yaxis type=log integer ;
text x=_prdate y=eventcount text=events
/ strip contributeoffsets=none rotate=90 position=topright
splitchar='|' splitpolicy=splitalways;
dropline x=_prdate y=eventcount /dropto=x;
run;
opå
Ou, Maybe you need summary it before plot it .
data WORK.EXAMPLE;
infile datalines delimiter=',' truncover dsd;
input prdate :date9. events:$100. count ;
_prdate=intnx('month',prdate,0);
format prdate _prdate ddmmyy8.;
if not missing(events) then do;
eventcount=count;
events=cats(events,'|(',put(prdate,ddmmyy10.),')');
end;
datalines4;
01Jan2020,., 0
27JAN2020,., 1050
28JAN2020,., 63721
29JAN2020,., 22812
30JAN2020,., 11121
01FEB2020,., 10511
02FEB2020,., 18180
11MAR2020,Lock down starts , 2345
15APR2020, Early reopening ,12356
15AUG2020,Compulsory use of masks in public transport ,46757
01SEP2020,Universities start , 34568
01OCT2020,., 3468
;;;;
proc summary data=example nway;
class _prdate events/missing;
var count eventcount;
output out=have sum=;
run;
ods graphics / noscale;
proc sgplot data=work.have noautolegend;
series x=_prdate y=count/smoothconnect ;
xaxis valuesformat=monname3.;
text x=_prdate y=eventcount text=events
/ strip contributeoffsets=none rotate=90 position=topright
splitchar='|' splitpolicy=splitalways;
dropline x=_prdate y=eventcount /dropto=x;
run;
@mmea wrote:
It works - but do not look good - is there tips and tricks to do something different so it will come out nicer?
Define "nicer".
You may want to go back to the first response where I specifically asked if you needed a "smoothing" function applied.
Which would likely have lead to a discussion about what type of smoothing needs to be applied, which would likely be dependent on the data that you have.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.