I have a program that attempts to define two macro variables - one being superscript 1 and one being superscript 2. The program then uses a CASE statement to determine if that superscript should be appended to a drug name for a later publication.
I am using this to define the global variables:
/* 1 superscript */
call symput('sup1',kcvt('00b9'x,'utf-16be','utf-16be'));
/* 2 superscript */
call symput('sup2',kcvt('00b2'x,'utf-16be','utf-16be'));
The CASE statements later do work, as I have another variable with a 'YES' or 'NO ' indicating whether the superscripts should be applied. And that works correctly for both superscripts. However, DRUG_NAME || "¹" appears to work correctly, giving me the drug name with a superscript 1 at the end. However, DRUG_NAME || “²” does not. I only get the drug name - no superscript. In addition, the program runs much slower and I am experiencing OutOfMemory errors when this is included. I don't know if this is program memory or log memory.
Am I defining superscript 2 incorrectly?
____________________
First case statement does not work. Second case statement does work:
select
case when E."Brand Name"n is null then PN1.Pub_Name else PN1.Pub_Name || "²" end as Pub_Name,
case when E."Brand Name"n is null then 'No ' else 'Yes' end as Strength_Exclusion
OK. I was able to get it to work, although I'm not sure I completely understand. Even though I used COMPRESS for my superscript values, I was still getting a blank space at the beginning. So I tried SUBSTR, looking for the second character only. That worked!
options validvarname=any;
proc sql;
create table work.DougTest (Drug char(50));
insert into work.DougTest
values('Aspirin')
values('Insulin');
run;
proc sql;
create table work.WithSuperscripts as
(select Drug, strip(Drug)||substr(compress(kcvt('00b9'x,'utf-16be','utf-16be')),2,1) as Super1,
strip(Drug)||substr(compress(kcvt('00b2'x,'utf-16be','utf-16be')),2,1) as Super2
from work.DougTest);
proc sql print; select * from work.WithSuperscripts;
It is best not to use hexadecimal characters in SAS macro variable values:
"Note: The SAS macro language does not support using hexadecimal values to specify non-printable characters."
SAS 9.4 Macro Language: Reference, Fifth Edition: Getting Started with the Macro Facility
Your goal is unclear, but maybe you can adapt something like this to your application:
ods escapechar='^';
data work.drug;
length drug $19 sup1 sup2 $10;
retain sup1 sup2;
infile cards;
input drug;
if (_n_) then do;
sup1 = '^{super 1}';
sup2 = '^{super 2}';
end;
if (drug eq 'Aspirin')
then drug = cats(drug, sup1);
else if (drug eq 'Ibuprofen')
then drug = cats(drug, sup2);
cards;
Aspirin
Ibuprofen
;
run;
proc print data=work.drug; run; quit;
Vince DelGobbo
SAS R&D
There may be an issue with how our SAS is set up. But it isn't recognizing the superscript part of '^{super 1}'. I did set '^' as the escapechar and ran your code, but the values are coming back simply as numbers.
1 | Aspirin1 | 1 | 2 |
2 | Ibuprofen2 | 1 | 2 |
Please post your full code, and the results of running this code:
%put &=SYSVLONG &=SYSSCPL;
proc print data=sashelp.vdest; run; quit;
Vince DelGobbo
SAS R&D
Running your code, I got this for results:
1 | TAGSETS.SASREPORT13(EGSR) | HTMLBlue |
Check the log for the results of the %PUT statement.
I suspect that the SASReport ODS destinations do not support things like superscripts.
Are you using SAS Enterprise Guide to run the code? If so, then turn on HTML output or PDF output to see the superscripts. Otherwise, manually issue an ODS statement for these destinations.
Vince DelGobbo
SAS R&D
Below is a small-scale version of what I am attempting to do. In my results, Super1 and Super2 are not showing the drug name and superscript attached correctly.
Aspirin | Aspirin ¹ | Aspirin ² |
Insulin | Insulin ¹ | Insulin ² |
options validvarname=any;
proc sql;
create table work.DougTest (Drug char(50));
insert into work.DougTest
values('Aspirin')
values('Insulin');
run;
proc sql;
create table work.WithSuperscripts as
(select Drug, Drug||compress(kcvt('00b9'x,'utf-16be','utf-16be')) as Super1,
Drug||compress(kcvt('00b2'x,'utf-16be','utf-16be')) as Super2
from work.DougTest);
proc sql print; select * from work.WithSuperscripts;
OK. I was able to get it to work, although I'm not sure I completely understand. Even though I used COMPRESS for my superscript values, I was still getting a blank space at the beginning. So I tried SUBSTR, looking for the second character only. That worked!
options validvarname=any;
proc sql;
create table work.DougTest (Drug char(50));
insert into work.DougTest
values('Aspirin')
values('Insulin');
run;
proc sql;
create table work.WithSuperscripts as
(select Drug, strip(Drug)||substr(compress(kcvt('00b9'x,'utf-16be','utf-16be')),2,1) as Super1,
strip(Drug)||substr(compress(kcvt('00b2'x,'utf-16be','utf-16be')),2,1) as Super2
from work.DougTest);
proc sql print; select * from work.WithSuperscripts;
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 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.