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

Hi,

 

I have the following problem:

 

I would like to calculate the mean per period of the following table :

test.PNG

I would like to get a table like this :

date.PNG Thank you for your help

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can create the date_semester variable and calculate mean by it:

data temp;
 set have;
       length semstr $7;
       mon = put(date,yymmn6.);
       if  '200507' le mon le '200512' then semstr = '2005_s2'; else
       if  '200601' le mon le '200606' then semstr = '2006_s1'; else
       if  '200606' le mon le '200612' then semstr = '2006_s2';
run;

proc means data=temp;
     class semstr;
     var    score_value;
     output out=want mean=;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

How are these periods defined? Why is june included in the last half year period in the first group but not in the last?

 

If you have a clear pattern of how your groups are defined, you can use PROC TIMESERIES.

 

Otherwise, use a data step to group the periods and use PROC MEANS.

Shmuel
Garnet | Level 18

You can create the date_semester variable and calculate mean by it:

data temp;
 set have;
       length semstr $7;
       mon = put(date,yymmn6.);
       if  '200507' le mon le '200512' then semstr = '2005_s2'; else
       if  '200601' le mon le '200606' then semstr = '2006_s1'; else
       if  '200606' le mon le '200612' then semstr = '2006_s2';
run;

proc means data=temp;
     class semstr;
     var    score_value;
     output out=want mean=;
run;
Ksharp
Super User

Use INTNX() to make a group variable then PROC SUMMARY.

 

data have;
input date : date9. value;
format date date9.;
cards;
05jun2017 21
12nov2017 43
21feb2016 32
21mar2017 3
;
run;

data have;
 set have;
 group=intnx('semiyear',date,0);
 format group date9.;
run;

proc summary data=have nway;
class group;
var value;
output out=want mean=;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1285 views
  • 4 likes
  • 4 in conversation