%macro prodlist(prodline);
%let prodline=%qupcase(&prodline);
title "Listing of %qsysfunc(propcase(&prodline, %str( &)))";
proc print data=mc1.products;
where upcase(Product_Line)="&prodline";
var Product_ID Product_name Product_Line;
run;
title;
%mend prodlist;
%prodlist (%nrstr(clothes&shoes))
In the provided code, when the %str( &) is present in the title statement, the title displayed in the report becomes "Listing of Clothes&Shoes."
On the other hand, if the %str( &) is omitted and the title statement is written as "title "Listing of %qsysfunc(propcase(&prodline))";", the title in the report appears as "Listing of Clothes&shoes."
I'm curious why, when %str( &) is omitted, the propcase function doesn't seem to apply to the word "Shoes" in the title. Could you please explain why this happens?
Suggestion: First, read the documentation for the PROPCASE function, do you know what the second parameter, when used, with propcase does?
Syntax
Required Argument
argument
specifies a character constant, variable, or expression.
Optional Argument
delimiter
specifies one or more delimiters that are enclosed in quotation marks. The default delimiters are blank, forward slash, hyphen, open parenthesis, period, and tab.
Tip If you use this argument, then the default delimiters, including the blank, are no longer in effect.
So the second parameter tells the Propcase function what to use to separate "words" before applying letter case change.
But the & is critical character and will get treated by the MACRO processor as the indicator of the start of a macro variable name. So the %str function masks the & from being treated as such and allows use as a delimiter instead of macro token. The standard list of delimiters used by the Propcase function are blank, forward slash, hyphen, open parenthesis, period, and tab. So the & is not a delimiter unless forced and the second "word" that people see is not treated as a separate word,
Now use this: Clothes socks&shoes as the value passed to macro. What should Propcase do to that? Or just test in a data step.
data junk; x=propcase('Clothes socks&shoes'); y=propcase('Clothes socks&shoes','&'); z=propcase('Clothes socks&shoes',' &'); run;
Without the %STR, & is interpreted as a macro trigger, but not as an argument to the PROPCASE function. Since PROPCASE then is not told that & is a word delimiter, the s in shoes stays lowercase.
Correction: since you omit the STR altogether, there ain't even a second argument to PROPCASE, so only the default delimiters (which do not include the ampersand) are used.
You don't need the %STR() for the & in the delimiter argument since it is not followed by a letter or digit it will not be confused for a macro trigger.
But you do need it for the space character.
Try it with
%str( )&
Instead of
%str( &)
and you should see the same results.
Suggestion: First, read the documentation for the PROPCASE function, do you know what the second parameter, when used, with propcase does?
Syntax
Required Argument
argument
specifies a character constant, variable, or expression.
Optional Argument
delimiter
specifies one or more delimiters that are enclosed in quotation marks. The default delimiters are blank, forward slash, hyphen, open parenthesis, period, and tab.
Tip If you use this argument, then the default delimiters, including the blank, are no longer in effect.
So the second parameter tells the Propcase function what to use to separate "words" before applying letter case change.
But the & is critical character and will get treated by the MACRO processor as the indicator of the start of a macro variable name. So the %str function masks the & from being treated as such and allows use as a delimiter instead of macro token. The standard list of delimiters used by the Propcase function are blank, forward slash, hyphen, open parenthesis, period, and tab. So the & is not a delimiter unless forced and the second "word" that people see is not treated as a separate word,
Now use this: Clothes socks&shoes as the value passed to macro. What should Propcase do to that? Or just test in a data step.
data junk; x=propcase('Clothes socks&shoes'); y=propcase('Clothes socks&shoes','&'); z=propcase('Clothes socks&shoes',' &'); run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.