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

Hi All,

I have three questions about layout data lattice.  I used sample dataset sashelp.cars to create the plot and attached it below.

1.  How to specify different colors and symbols for values of DriveTrain, "All", "Front", and "Rear"?

2. There are two panels named "SUV" and "Sedan" in the plot.  How to show their variable name "Type" on the top like "Cylinders"?

3. How to make the sidebar located at the right top corner of this plot?

I hope everything makes sense to you.  Thanks!

proc sql;
create table CARS as
select * 
from sashelp.cars
where Type = "SUV" or Type = "Sedan";
quit;

proc template;
define statgraph scatter;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
entrytitle halign=left textattrs=(size=15pt) "Plot";
layout datalattice rowvar=Type / 
				   headerlabeldisplay=value rowheaders=left
                   rowaxisopts=(display=standard griddisplay=on gridattrs=(pattern=dash) labelposition=top labelattrs=(size=11pt)) 
				   columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
				   headerbackgroundcolor=CXD1D0CE headerborder=false headerlabelattrs=(size=11pt weight=normal color=CX000000);
layout prototype;
scatterplot x=MPG_City y=Cylinders / group=DriveTrain markerattrs=(color=CXC11B17 symbol=circlefilled) name='a';
endlayout;
sidebar / align=bottom spacefill=false;
	discretelegend "a" / border=false valueattrs=(size=11pt) title="DriveTrain";
endsidebar;
endlayout;
endgraph;
end;
run;

proc sgrender data=CARS template=scatter;
run;

Capture_Car.PNG 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

1.  How to specify different colors and symbols for values of DriveTrain, "All", "Front", and "Rear"?

[Dan] - If you care about which color and symbols are associated with each value, use a DiscreteAttrMap; otherwise, you can change the colors and symbols using the DATACONTRASTCOLORS and DATASYMBOLS options on the BEGINGRAPH statement.

 

2. There are two panels named "SUV" and "Sedan" in the plot.  How to show their variable name "Type" on the top like "Cylinders"?

[Dan] - Use a DATAPANEL with COLUMNS=1 (the default) instead of a DATALATTICE.

 

3. How to make the sidebar located at the right top corner of this plot?

[Dan] - There is not a nice way to do this. I would recommend keeping the legend at the bottom to optimize your space.

 

Below are the recommended changes to your code.

 

Hope this helps!

Dan

 

proc sql;
create table CARS as
select *
from sashelp.cars
where Type = "SUV" or Type = "Sedan";
quit;

proc template;
define statgraph scatter;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
entrytitle halign=left textattrs=(size=15pt) "Plot";
discreteattrmap name="scatmap";
   value "All" / markerattrs=(color=orange symbol=circlefilled);
   value "Front" / markerattrs=(color=purple symbol=circlefilled);
   value "Rear" / markerattrs=(color=green symbol=circlefilled);
enddiscreteattrmap;
discreteattrvar attrvar=mapvar var=Drivetrain attrmap="scatmap";
layout datapanel   classvars=(Type) /
        headerlabeldisplay=value
        rowaxisopts=(display=standard griddisplay=on gridattrs=(pattern=dash) labelposition=top labelattrs=(size=11pt))
        columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
        headerbackgroundcolor=CXD1D0CE headerborder=false headerlabelattrs=(size=11pt weight=normal color=CX000000);
layout prototype;
scatterplot x=MPG_City y=Cylinders / group=mapvar name='a';
endlayout;
sidebar / align=bottom spacefill=false;
	discretelegend "a" / border=false valueattrs=(size=11pt) title="DriveTrain";
endsidebar;
endlayout;
endgraph;
end;
run;

proc sgrender data=CARS template=scatter;
run;

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

1.  How to specify different colors and symbols for values of DriveTrain, "All", "Front", and "Rear"?

[Dan] - If you care about which color and symbols are associated with each value, use a DiscreteAttrMap; otherwise, you can change the colors and symbols using the DATACONTRASTCOLORS and DATASYMBOLS options on the BEGINGRAPH statement.

 

2. There are two panels named "SUV" and "Sedan" in the plot.  How to show their variable name "Type" on the top like "Cylinders"?

[Dan] - Use a DATAPANEL with COLUMNS=1 (the default) instead of a DATALATTICE.

 

3. How to make the sidebar located at the right top corner of this plot?

[Dan] - There is not a nice way to do this. I would recommend keeping the legend at the bottom to optimize your space.

 

Below are the recommended changes to your code.

 

Hope this helps!

Dan

 

proc sql;
create table CARS as
select *
from sashelp.cars
where Type = "SUV" or Type = "Sedan";
quit;

proc template;
define statgraph scatter;
begingraph / backgroundcolor=CXD1D0CE border=true borderattrs=(color=CXEDDA74 thickness=5);
entrytitle halign=left textattrs=(size=15pt) "Plot";
discreteattrmap name="scatmap";
   value "All" / markerattrs=(color=orange symbol=circlefilled);
   value "Front" / markerattrs=(color=purple symbol=circlefilled);
   value "Rear" / markerattrs=(color=green symbol=circlefilled);
enddiscreteattrmap;
discreteattrvar attrvar=mapvar var=Drivetrain attrmap="scatmap";
layout datapanel   classvars=(Type) /
        headerlabeldisplay=value
        rowaxisopts=(display=standard griddisplay=on gridattrs=(pattern=dash) labelposition=top labelattrs=(size=11pt))
        columnaxisopts=(griddisplay=on gridattrs=(pattern=dash) labelattrs=(size=12pt weight=normal))
        headerbackgroundcolor=CXD1D0CE headerborder=false headerlabelattrs=(size=11pt weight=normal color=CX000000);
layout prototype;
scatterplot x=MPG_City y=Cylinders / group=mapvar name='a';
endlayout;
sidebar / align=bottom spacefill=false;
	discretelegend "a" / border=false valueattrs=(size=11pt) title="DriveTrain";
endsidebar;
endlayout;
endgraph;
end;
run;

proc sgrender data=CARS template=scatter;
run;
Relax
Fluorite | Level 6

Thanks for your help, Dan

All of them work well now

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 979 views
  • 0 likes
  • 2 in conversation