I am using SAS 9.2.
Is there a way to use the str(%’) syntax when I use the %let statement on a marco? Detail is below.
First I created max_level_name; by the below code.
SELECT total, &enrRepTy, °OrStudIDTy into :max_level_total, :max_level_name, :max_deg_Or_stud_id
from
( select sum(students_enrolled) as total, &enrRepTy, °OrStudIDTy
from enrollment
&whereClause
group &enrRepTy, °OrStudIDTy)
having total = max(total);
I found that when I outputted &max_level_name in a dynamic title statement as
dynamic title2="excluding &max_level_name ";
that SAS has a bug that splits my title text e.g.
Baccalaureate only becomes
Baccalaureate
only
I found a crazy work around by creating a new variable and saving the value into the new variable. Note there are no trailing or leading spaces in my dataset.
%let displaymaxlevelname = &max_level_name;
My crazy work around worked fine until I changed my selection from Baccalaureate to Master’s adding the apostrophe. Where it blows up due to a Literal contains unmatched quote error. Is there a way to use the str(%’) syntax when I use the %let statement on a marco?
Is there a way that I do not have to do the intermediary step?
Instead of TRIMMED use SEPARATED BY ' '
You also might want to protect against embedded double quote characters by using QUOTE() function.
title2=%sysfunc(quote(excluding &max_level_name));
1) You can remove the leading/trailing spaces by changing your SQL syntax. If you are using a relative new version of SAS use the TRIMMED option. For an older version use SEPARATED BY clause.
SELECT total
, &enrRepTy
, °OrStudIDTy
into :max_level_total trimmed
, :max_level_name trimmed
, :max_deg_Or_stud_id trimmed
2) You can use %SUPERQ() to quote the value of your macro variable.
%let max_level_name=%superq(max_level_name) ;
I am using SAS 9.2 the feature trimmed does not appear to be in SAS 9.2
If I use %superq it returns to the odd spacing.
Instead of TRIMMED use SEPARATED BY ' '
You also might want to protect against embedded double quote characters by using QUOTE() function.
title2=%sysfunc(quote(excluding &max_level_name));
Separated by ‘’ solved it.
When I used title2=%sysfunc(quote(excluding &max_level_name)); it blew up.
Did you have the line to quote the value with %SUPERQ() to protect the unbalanced quotes? If not you could include here:
title2=%sysfunc(quote(excluding %superq(max_level_name)));
No, I only used separated by ‘ ‘.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.