BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sourabhy
Calcite | Level 5
i need to know.. how to solve this querry
countrywise breakup of
most purchased product
least purchased product
since i am fresher in sas kindly help..
1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
ballardw
Super User

"Most purchased product" would require a definition. It could represent 1) frequency of purchase, 2) total currency value of purchases, 3) largest numbers of unique purchasers and likely a few more ideas depending on what the "product" concerns.

 

as a minimum a description of your data would help provide more targeted suggestions, best is some example data in the form of a data step.

 

Also, do you want/need a data step to provide input to a model or further data processing or do you want a report that people will read?

 

I would likely look at starting with Proc summary with your country and product variables as CLASS variables and what ever you are using to measure "most" or "least" as VAR variable that gets summed. I would likely use the NWAY option as well unless I wanted sums of the VAR variables overall, by country regardless of product and by product regardless of country.

sourabhy
Calcite | Level 5

data new;

input productid $ country $ quantity 5.;

datalines;

 

22139 UK 56

21773 UK 4

21773 UK 5

21801 UK 34

21056 SA 1

21773 SA 34

34788 MN 345

3456 MN 234

;

 

I need table given below:

title "most purchased product"

country   productid       maxqty(as per quantity)

UK          22139            56

SA          21773            34

MN         34788            345

similarly for least purchased product

didn't got the same output.

kindly help

Kurt_Bremser
Super User

Try

proc sql;
create table want as
select country, productid, max(quantity) as maxqty
from new
group by country
having quantity = max(quantity);
quit;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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