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
( select sum(students_enrolled) as total, &enrRepTy, °OrStudIDTy
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
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?
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.
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) ;
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.