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

Hi

i am new base SAS programming, i want to calculate countrywise monthly sale with base sas or proc sql method.

data as below

this is retail.CSV file.

Country Product_id unitPrice Quantity Date

AU  2507 3.32 6 01/12/2017

AU 2510 4.11 7 01/12/2017

AU 2507 3.32 3 05/12/2017

US 2411 5.22 4 04/11/2017

US 2466 3.11 6 06/10/2017

Ge 2658 4.58 7 07/09/2017

Ge 6655 6.32 2 07/09/2017

US 8425 1.23 9 05/08/2017

AU 3512 3.22 10 06/06/2017

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

See this:

data have;
input Country $ Product_id $ unitPrice Quantity Date :mmddyy10.;
format date mmddyy10.;
cards;
AU  2507 3.32 6 01/12/2017
AU 2510 4.11 7 01/12/2017
AU 2507 3.32 3 05/12/2017
US 2411 5.22 4 04/11/2017
US 2466 3.11 6 06/10/2017
Ge 2658 4.58 7 07/09/2017
Ge 6655 6.32 2 07/09/2017
US 8425 1.23 9 05/08/2017
AU 3512 3.22 10 06/06/2017
;
run;

proc sql;
create table want as
select
  country,
  year(date) as year,
  month(date) as month,
  sum(quantity*unitprice) as sale
from have
group by country, calculated year, calculated month;
quit;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

See this:

data have;
input Country $ Product_id $ unitPrice Quantity Date :mmddyy10.;
format date mmddyy10.;
cards;
AU  2507 3.32 6 01/12/2017
AU 2510 4.11 7 01/12/2017
AU 2507 3.32 3 05/12/2017
US 2411 5.22 4 04/11/2017
US 2466 3.11 6 06/10/2017
Ge 2658 4.58 7 07/09/2017
Ge 6655 6.32 2 07/09/2017
US 8425 1.23 9 05/08/2017
AU 3512 3.22 10 06/06/2017
;
run;

proc sql;
create table want as
select
  country,
  year(date) as year,
  month(date) as month,
  sum(quantity*unitprice) as sale
from have
group by country, calculated year, calculated month;
quit;
Raavi2507
Calcite | Level 5
Thanks for help .. this is very useful

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
  • 2 replies
  • 872 views
  • 0 likes
  • 2 in conversation