I am using PROC PSMATCH to make a standardized mean difference plot, and I want to know if it is possible to change the label of the variable, as the plot just uses the variable's default name. This is some SAS code I used to make a standardized mean difference plot on the CARS dataset using PROC PSMATCH.
data CARS;
set sashelp.CARS;
format CAR_TYPE $50.;
if TYPE = 'SUV' then CAR_TYPE = 'SUV';
if TYPE = 'Sedan' then CAR_TYPE = 'SEDAN';
if CAR_TYPE ne ' ';
run;
ods graphics on;
proc psmatch data=CARS region=cs;
class CAR_TYPE;
psmodel CAR_TYPE(Treated="SUV")=MPG_CITY;
match method=optimal(k=1)
distance=mah(lps)
caliper=.
weight=none;
assess lps var=(MPG_CITY);
run;
For example, is it possible to change "MPG_City" to "Mpg in the City" in this plot?
Thank you in advance for any help or advice!
Mmm there might be no way to use a label.
Maybe like this if your site supports name literals (please don't use them unless necessary*)?
proc psmatch data=CARS(rename=(MPG_CITY='MPG In City'n)) region=cs;
class CAR_TYPE;
psmodel CAR_TYPE(Treated="SUV")='MPG In City'n;
match method=optimal(k=1)
distance=mah(lps)
caliper=.
weight=none;
assess lps var=('MPG In City'n);
run;
* IMPORTANT Throughout SAS, using the name literal syntax with variable names that exceed the 32-byte limit or have excessive embedded quotation marks might cause unexpected results. The intent of the VALIDVARNAME=ANY system option is to enable compatibility with other DBMS variable (column) naming conventions, such as allowing embedded blanks and national characters. See https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm
Mmm there might be no way to use a label.
Maybe like this if your site supports name literals (please don't use them unless necessary*)?
proc psmatch data=CARS(rename=(MPG_CITY='MPG In City'n)) region=cs;
class CAR_TYPE;
psmodel CAR_TYPE(Treated="SUV")='MPG In City'n;
match method=optimal(k=1)
distance=mah(lps)
caliper=.
weight=none;
assess lps var=('MPG In City'n);
run;
* IMPORTANT Throughout SAS, using the name literal syntax with variable names that exceed the 32-byte limit or have excessive embedded quotation marks might cause unexpected results. The intent of the VALIDVARNAME=ANY system option is to enable compatibility with other DBMS variable (column) naming conventions, such as allowing embedded blanks and national characters. See https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm
Hi Chris,
This worked! Thank you so much for your help. It's useful how SAS has these name literals to allow special characters and flexibility in variable names. However, it is a bit of a pain to have to change the name of each variable to the name literal each time the variable is referenced.
I found this sample code that stores the name literals into macro variables, so that may be helpful if you need to make multiple name literals for multiple variables.
https://support.sas.com/kb/48/278.html
Thanks again for your help!
I found this post helpful. I however noticed that labels with space in them e.g. 'Government insurance'n did not work because of the space in between. If I put a hyphen '_' between, it worked bu that does not fit the purpose
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.