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

Hi All

 

I am trying to calculate AVERAGE MONTHLY PRICE using the PROC SQL Code but stryggling to get the right coding.

 

The data looks like this :

 

Dates                    Amount

01Jul1994            1000

02MAY1995         1500

10MAY1995         2000

09JUN1995         3000

27JUN1995         3500

.

.

.

.

.

.AND SO ON FOR DIFFENRENT MONTHS IN DIFFERENT YEARS.

How to go abou it? Any suggestion will be helpfull

 

Thanks a ton in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input Dates : date9.     Amount;
format dates date.;
cards;
01Jul1994            1000
02MAY1995         1500
10MAY1995         2000
09JUN1995         3000
27JUN1995         3500
;
run;
proc summary data=have nway;
class dates;
format dates monyy7.;
var amount;
output out=want mean=;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Create a variable called MONTH, you can use the MONTH function in SAS to do this. Also create a variable called YEAR, using the YEAR function in SAS.

 

Then run PROC MEANS or PROC SUMMARY with YEAR and MONTH as CLASS variables.

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

proc sql;
  create table WANT as
  select MNTH,
         avg(AMOUNT) as AVG
  from   (select month(DATES) as MNTH,AMOUNT from HAVE)
  group by MNTH;
quit;
Kurt_Bremser
Super User

Something like

proc sql;
create table want as
  select put(dates,yymmn6.) as yymm, mean(amount) as mean_price
  from have
  group by calculated yymm
;
quit;

??

Ksharp
Super User
data have;
input Dates : date9.     Amount;
format dates date.;
cards;
01Jul1994            1000
02MAY1995         1500
10MAY1995         2000
09JUN1995         3000
27JUN1995         3500
;
run;
proc summary data=have nway;
class dates;
format dates monyy7.;
var amount;
output out=want mean=;
run;
PaigeMiller
Diamond | Level 26

@Ksharp wrote:
data have;
input Dates : date9.     Amount;
format dates date.;
cards;
01Jul1994            1000
02MAY1995         1500
10MAY1995         2000
09JUN1995         3000
27JUN1995         3500
;
run;
proc summary data=have nway;
class dates;
format dates monyy7.;
var amount;
output out=want mean=;
run;

Certainly a superior method than what I described above.

--
Paige Miller

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
  • 5 replies
  • 4069 views
  • 1 like
  • 5 in conversation