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

Hi,

Can anyone please help me with the following :

I have data, where customers spending more than$100 is rewaded. I need to create 3 datasets(d1 d2 d3),the variable order_type indicates whether sale was retail(=1),catalog(=2),internet(=3).the variable total_retail_price is the amount the customer spends on each individual order. I need to create variable totsales to hold total sales to each customer by order_type.A customer can output to more than 1 dataset if he spents $100  or more in retail  and internet.

data s;
set blib.usorders04;
where total_retail_price>100;
run;
proc sort data=s out=s1;
by order_type;
run;
data d1 d2 d3;
set s1;
totsales=sum(total_retail_price);
by order_type;
if order_type=1 then output d1;
if order_type=2 then output d3;
if order_type=3 then output d3;
proc print data=d1;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Let's start with this part

 

I need to create 3 datasets(d1 d2 d3)

 

This makes the rest of your problem more difficult to code, and in fact is completely unnecessary (and a bad idea as well). Keep everything in one data set.

 

Now that we have skipped the unnecessary creation of separate data sets, you can do the summing very easily

 

proc summary data=blib.usorders04(where=(total_retail_price>100)) nway;
    class order_type customer;
    var total_retail_price;
    output out=want sum=total_sales;
run;

 

The output data set that I have named WANT has everything you need.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Let's start with this part

 

I need to create 3 datasets(d1 d2 d3)

 

This makes the rest of your problem more difficult to code, and in fact is completely unnecessary (and a bad idea as well). Keep everything in one data set.

 

Now that we have skipped the unnecessary creation of separate data sets, you can do the summing very easily

 

proc summary data=blib.usorders04(where=(total_retail_price>100)) nway;
    class order_type customer;
    var total_retail_price;
    output out=want sum=total_sales;
run;

 

The output data set that I have named WANT has everything you need.

--
Paige Miller
archita
Fluorite | Level 6

thanks, it is working.

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 16. 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
  • 2 replies
  • 609 views
  • 0 likes
  • 3 in conversation