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;
This is the graph; which IS what I want... But only need the top 5 countries, not all of them.
Thanks!
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.
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.
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?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.