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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 308 views
  • 0 likes
  • 3 in conversation