BookmarkSubscribeRSS Feed
DanniekvLith
Calcite | Level 5

Dear sas users!

 

I have a question regarding calculating averages between dates in my dataset.

My dataset is as followed:

 

whereby datum= date, tijd=time, bedrijf=company, temp=temperature, luchtvochtigheid=humidity, CO2=carbon dioxide and NH3= ammonia

DanniekvLith_0-1654253722396.png

 

I have data from 12 weeks whereby every 10 minutes data from senors is logged. I have this for in total 10 companies. Now I want to calculate a 2 week average value for the 4 variables (humidity, temperature, CO2 and NH3) per company. Time is not important in this case. 

 

so for each company I want an avarage value for every 2 weeks (thus 6 average values per company) (this is because clinical analysis to the research object were done were I want to connect climate data to).

 

I am not sure how to do this. Does anyone maybe have an idea? 

 

Thankyou in advance!

 

Kind regards,

 

Danniek

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Use custom formats to identify the two week time periods, and then use PROC SUMMARY to compute the means.

 

EXAMPLE:

 

/* UNTESTED CODE */

proc format;
    value twoweek '06MAY2022'd-'19MAY2022'd='06MAY2022'
        '20MAY2022'd-'02JUN2022'd='20MAY2022' /* etc. */
    ;
run;

proc summary data=have way;
    class bedrijf datum; 
    format datum twoweek.;
    var temp luchtvochtigheid co2 nh3;
    output out=stats mean=;
run;

 

 

NOTE: We cannot write code to test against data in screen captures. If you want tested code, then you need to provide the data as working SAS data step code (instructions), and not in any other format.

--
Paige Miller
ballardw
Super User

I have worked with data logger data similar to this. I would suggest a short investigation of your values around midnight/date change. You may have some cases where the "time" component indicates it is one of before/after midnight that doesn't quite agree with the "date" value depending on exactly how you want to consider date for the calculations.

 

In my case my data loggers were collecting a string of "hourly" values but had 25 hours per day: 00 to 24. The kicker was that the hour 24 values of day 1 were not the same as the hour 00 values for day 2. So some adjustments for some statistics that were really expecting 24 hourly measures had to be made.

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
  • 2 replies
  • 391 views
  • 2 likes
  • 3 in conversation