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

Hey everyone, 

 

First time posting on here, as I am new to SAS. 

 

My dataset is about toy sales for different facilities by country.

 

I have to plot the data using SGPLOT but want to limit the lines on the graph to the top 5 facilities instead of including all 30 countries.

 

Here is my code so far.

 

proc freq data=mis543.toys order=freq;
tables facilitycountry;
run;

(The above code shows me sales by country in descending order)

 

title "Toys Sold by Location in 2017";
proc sgplot data=mis543.toys;
series x=transactionmonth y=productpriceactual / group=facilitycountry;
run;
title;

SGPLOT.PNG

This is the graph; which IS what I want... But only need the top 5 countries, not all of them.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You will have to filter the data somehow.

If you want that done "automagicly" by the code then you write code to identify/select the records you want and either add a variable to your plot data set to indicate the records to use for plotting use that information to write the code for Prog Sgplot or combination.

Or you identify manually the values of your group variable to plot and put them in the code. Such as use that Proc Freq output to get the values and write something like

title "Toys Sold by Location in 2017";
proc sgplot data=mis543.toys;
   where facilitycountry in ("firstname" "secondname" "third" "fourth" "fifth");
   series x=transactionmonth y=productpriceactual / group=facilitycountry;
run;
title;

The Where statement is usable in almost every procedure so isn't listed in each proc. It is used to filter data.

If you have not seen the IN operator it is like writing a bunch of

If Var=1 or Var=2 or Var=3 or var=4 or var=77;

equivalent where
where var in (1 2 3 4 77);

I assumed your "facilitycountry" is text but if it is numeric just use the number values.

View solution in original post

4 REPLIES 4
ballardw
Super User

You will have to filter the data somehow.

If you want that done "automagicly" by the code then you write code to identify/select the records you want and either add a variable to your plot data set to indicate the records to use for plotting use that information to write the code for Prog Sgplot or combination.

Or you identify manually the values of your group variable to plot and put them in the code. Such as use that Proc Freq output to get the values and write something like

title "Toys Sold by Location in 2017";
proc sgplot data=mis543.toys;
   where facilitycountry in ("firstname" "secondname" "third" "fourth" "fifth");
   series x=transactionmonth y=productpriceactual / group=facilitycountry;
run;
title;

The Where statement is usable in almost every procedure so isn't listed in each proc. It is used to filter data.

If you have not seen the IN operator it is like writing a bunch of

If Var=1 or Var=2 or Var=3 or var=4 or var=77;

equivalent where
where var in (1 2 3 4 77);

I assumed your "facilitycountry" is text but if it is numeric just use the number values.

mccusker1818
Fluorite | Level 6
So what if I needed to predict the following 3 months sales for each location using PROC FORECAST?
ballardw
Super User

Not a user of Proc Forecast.

Likely the way would be to sort the data by location and then us BY location to get a forecast for each location.

 


@mccusker1818 wrote:
So what if I needed to predict the following 3 months sales for each location using PROC FORECAST?

 

mccusker1818
Fluorite | Level 6
So would I use PROC SORT to sort the data by location?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1535 views
  • 1 like
  • 2 in conversation