BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PrimeDougR
Fluorite | Level 6

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 || "&sup1" appears to work correctly, giving me the drug name with a superscript 1 at the end.  However, DRUG_NAME || “&sup2” 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 || "&sup2" end as Pub_Name,
case when E."Brand Name"n is null then 'No ' else 'Yes' end as Strength_Exclusion

1 ACCEPTED SOLUTION

Accepted Solutions
PrimeDougR
Fluorite | Level 6

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;

View solution in original post

7 REPLIES 7
Vince_SAS
Rhodochrosite | Level 12

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

https://go.documentation.sas.com/?docsetId=mcrolref&docsetTarget=p1ccprwibo8gvqn1q6zinvjlzuut.htm&do...

 

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

PrimeDougR
Fluorite | Level 6

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.

 

Obs drug sup1 sup2
1Aspirin112
2Ibuprofen212
Vince_SAS
Rhodochrosite | Level 12

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

PrimeDougR
Fluorite | Level 6

Running your code, I got this for results:

 

Obs destination style
1TAGSETS.SASREPORT13(EGSR)

HTMLBlue

Vince_SAS
Rhodochrosite | Level 12

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

PrimeDougR
Fluorite | Level 6

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.

 

Drug Super1 Super2
AspirinAspirin
¹
Aspirin
²
InsulinInsulin
¹
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;

PrimeDougR
Fluorite | Level 6

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: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2465 views
  • 1 like
  • 2 in conversation