Looking at this:
title 'Mileage Distribution by Origin'; proc sgplot data=multiVar; density mpg_usa / legendlabel='USA' lineattrs=(pattern=solid); density mpg_asia / legendlabel='Asia' lineattrs=(pattern=solid); density mpg_eur / legendlabel='Europe' lineattrs=(pattern=solid); keylegend / location=inside position=topright across=1; xaxis display=(nolabel); run;
Here mpg_usa, mpg_asia and mpg_eur are separate columns. Can I also create separate plots like this if I have one column X and one group/class column in one plot? Hope this makes sense?
Yes. Density plot supports GROUP option. The option was added after the writing of this example.
title 'Mileage Distribution by Origin'; proc sgplot data=sashelp.cars; density mpg_city / group=origin lineattrs=(pattern=solid); keylegend / location=inside position=topright across=1; xaxis display=(nolabel); run;
I have the suspicion that this is a 9.4 SAS version feature as I am getting:
ERROR 22-322: Syntax error, expecting one of the following: ;, FREQ, LEGENDLABEL, LINEATTRS, NAME, SCALE, TRANSPARENCY, TYPE,
ERROR 76-322: Syntax error, statement will be ignored.
with an older version of sas ...
For an example of using the GROUP= option, see the second example at
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.
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.