BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

Hi. 

I have this example dataset (In my real dataset I have different 355 combinations)

 

 

 

 

 

 

 

 

10 REPLIES 10
ballardw
Super User

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

mmea
Quartz | Level 8

Is should basically be the number of tested - if thats possible?

ballardw
Super User

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.

Ksharp
Super User
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;

x.png

Ksharp
Super User
There are some outliers in your data. remove these extreme large data at xaxis .
and do't forget PROC SORT + BY prdate ,before PROC SGPLOT .
Ksharp
Super User
Notice , I used "x=_prdate " NOT "x=prdate " . _prdate is a new variable I made in data step.
mmea
Quartz | Level 8

opå

Ksharp
Super User

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;

x.png

ballardw
Super User

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

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 10 replies
  • 1331 views
  • 0 likes
  • 3 in conversation