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

New to SAS.

I currently need to summarize some data and know what is the average price of each month.

I have data like this:

Date    /   Price

19-05-23   50

19-05-23   80

19-05-24   50

19-05-25 ..........cont.

 

I would like to have a dataset like this:

Month   /  Average Price

May 2019   70

Jun 2019    90 ....

 

Please help! A million thanks!!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @vitalam89 

 

SQL is very simple too 

 


data have;
input date :date9. price;
format date date9.;
cards;
01jul1994 10
02may1995 15
10may1995 20
16jun1995 25
28jun1995 30
;

proc sql;
create table want as
select put(date,monyy7.) as Month_year, avg(price) as Average_price
from have
group by Month_year;
quit;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS Community 🙂

 

Do something like this

 

data have;
input date :date9. price;
format dates date9.;
cards;
01jul1994 10
02may1995 15
10may1995 20
16jun1995 25
28jun1995 30
;

proc summary data=have nway;
  class date;
  format date monyy7.;
  var price;
  output out=want(drop=_TYPE_ _FREQ_) mean=;
run;
novinosrin
Tourmaline | Level 20

Hi @vitalam89 

 

SQL is very simple too 

 


data have;
input date :date9. price;
format date date9.;
cards;
01jul1994 10
02may1995 15
10may1995 20
16jun1995 25
28jun1995 30
;

proc sql;
create table want as
select put(date,monyy7.) as Month_year, avg(price) as Average_price
from have
group by Month_year;
quit;
vitalam89
Calcite | Level 5
Thank you very much!

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