DATA Step, Macro, Functions and more

how to search if subscript is available in data values of character variables in sas

Reply
Occasional Contributor
Posts: 11

how to search if subscript is available in data values of character variables in sas

Dear All,

 

Could you please assist ? 

I need your asssustance to know how can we search if subscipt is available in data values of character variables in sas ?

 

For instance,   I have data values in my char variable in sas table like  service mark  and trademark ™  , In both the words you can see subcript .

 

so in case if i want to find wheather the word that i am reading have subcript or not then how can i do it in SAS? and then once find how to access and save in seperate variable.

 

Please assist.

Super User
Super User
Posts: 7,988

Re: how to search if subscript is available in data values of character variables in sas

Do they display that way in the dataset?  Just checking as some setups wouldn't show the superscript.

If it does then simple string processing functions like index, findw etc. should be sufficient.  Without some information however can't really go any furher.

http://support.sas.com/publishing/pubcat/chaps/59343.pdf

Occasional Contributor
Posts: 11

Re: how to search if subscript is available in data values of character variables in sas

Hi RW9,

 

Thanks for your quick reply.

 

I am able to read those superscript in dataset(Attached file) but without searching specific superscript , Can we check wheather superscript is present in my variable data values.

 

data test1;
set test;
position=find(DrugName,'®');
run;

 

or

 

Saving the superscript in new variable:

 

data test2;
set test;
position=substr(DrugName,find(DrugName,'®'));
run;

 

Using the above code, I am able to find the position or save the subscript but here i am searching the specific superscript. But i dont know , list of posible superscript that could come in variable values. so i need to find if superscript is present or not.

 

Can we search ^ (superscript ) if present then retrive position without specifying any superscript present in data values.? Any specific function or statement that can be used to accomplish this task.

 

please assist.

Super User
Super User
Posts: 7,988

Re: how to search if subscript is available in data values of character variables in sas

Yes, it doesn't work like that, there is no rtf tag ^{super} in the data, it runs of character sets.  All characters have a character table associated, e.g. ASCII, UTF16 etc.  These define what is displayed when the number (characters are actually a number refering to the table) is displayed when it encounters the number:

https://en.wikipedia.org/wiki/ASCII

https://en.wikipedia.org/wiki/UTF-32

http://www.fileformat.info/info/charset/UTF-16/list.htm

So if you know the character number for the super script characters then you can search for that.  I don't know offhand what these are, I strongly advise (and DM clean these things as well) that special characters do not appear in the data.  It can cause all kinds of problems.

Maybe this doc will help:

http://www.lexjansen.com/pharmasug/2010/CC/CC19.pdf

You could also try the compress() function e.g:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm

want=compress(have," ","acdf");
Frequent Contributor
Posts: 100

Re: how to search if subscript is available in data values of character variables in sas

data sample;
  symbol="This is the Copyright symbol"||'00A9'X;
  word=substr(symbol,1,find(symbol,'00A9'X));
  Unicode=substr(Symbol,find(symbol,'00A9'X);
run;
Occasional Contributor
Posts: 11

Re: how to search if subscript is available in data values of character variables in sas

Posted in reply to ShiroAmada

Hi ShiroAmada

 

Here in your example you are searching for specific supercript but i have many list of superscript.

 

In first step, can we check if supercript is present in data values or not? if it is present then store the position in variable.

 

is it possible?

Respected Advisor
Posts: 4,173

Re: how to search if subscript is available in data values of character variables in sas

@Ashish_S

Forget about superscript. That's formatting of characters which you won't have in your string of characters. The only thing you're having are characters so the only thing you can do is search for specific characters. 

What you would need is define the list of characters you're searching for (your "superscripts").

Ask a Question
Discussion stats
  • 6 replies
  • 82 views
  • 4 likes
  • 4 in conversation