BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TheSASNovice
Calcite | Level 5

I'm manipulating an existing dataset using PROC TIMESERIES - specifically aggregating 5 minute values into hours and doing this many days.

 

When I try plotting the hours there are some values being plotted that are not supposed to be there, and I can't find them in the dataset either.

 

PROC TIMESERIES data=examlib.china out=a3;
id dato_tid interval=hour
accumulate=total
setmissing=missing; 
var antal;
run;
data a4; 
set a3;
hh=hour(dato_tid);
dd=weekday(datepart(dato_tid));
run;
PROC SGPLOT data=a4;
series x=hh y=antal;
run;

getting this plot, with wrong values also printed in

image.png

Trying to locate these values in the dataset yields no results.

PROC PRINT data=a4;
var antal;
where hh=10 and antal<600;
run;

image.png

The only thing it finds is the missing values (there is a day with missing values), but none of the plotted values which are non-zero.

 

Any ideas what I'm doing wrong here? Any and all help much appreciated 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You are just looking at the line joining consecutive days. Try this instead;

 

data a4; 
set a3;
hh=timepart(dato_tid);
dd=datepart(dato_tid);
run;

PROC SGPLOT data=a4;
series x=hh y=antal / group=dd lineattrs=(pattern=solid color=blue);
run;

(untested)

 

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

You are just looking at the line joining consecutive days. Try this instead;

 

data a4; 
set a3;
hh=timepart(dato_tid);
dd=datepart(dato_tid);
run;

PROC SGPLOT data=a4;
series x=hh y=antal / group=dd lineattrs=(pattern=solid color=blue);
run;

(untested)

 

PG
TheSASNovice
Calcite | Level 5

Fantastic. Thanks so much mate! 🙂

 

image.png

 

I guess the only thing I need to fix is the xaxis, as it should ideally be showing hours. I will try to work in this 🙂

 

These are hourly traffic stats btw, for anyone interested 🙂

 

EDIT:

Converting to hours was easy. One small change in code:

data a4; 
set a3;
hh=timepart(dato_tid);
dd=datepart(dato_tid);
hh=hh/3600; *convert to hour format by dividing by seconds in hour;
run;

PROC SGPLOT data=a4;
series x=hh y=antal / group=dd lineattrs=(pattern=solid color=blue);
run;

image.png

Thanks 🙂

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 2 replies
  • 831 views
  • 1 like
  • 2 in conversation