DATA Step, Macro, Functions and more

Scan string

Reply
Contributor
Posts: 33

Scan string

Hi all,

I need to scan a column to find all the chacters within each string. The data is in hindi so they are all double byte characters. So what I need is really all the Hindi characters used on the column. I need a way of scan each string row and find the double byte character then output that chracter and then move on to the next character and so on...


Thanks in advance
Super Contributor
Super Contributor
Posts: 3,174

Re: Scan string

Suggest you review the SAS National Language Support (NLS) companion documentation. I expect you can use the SUBSTR function in a DO loop UNTIL you reach the LENGTH (function) of the SAS CHARACTER type variable.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search argument, this topic/post:

sas national language support dbcs unicode site:sas.com
Contributor
Posts: 33

Re: Scan string

My sas is already setup to view the characters, but im not sure i would extract all the characters from the string....for exmaple

_row_
abcdefgh

output should be
a
b
c
d
e
g
h

remember in reality these are doubly byte characters. Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Scan string

What is _row_? Maybe a SAS column/variable? Definitely, I expect you can easily parse the SAS character variable using SUBSTR function, creating individual character variables/columns, as you require, also to generate individual observations within a DO / END using some IF THEN OUTPUT; logic within the DO/END paragraph, as suggested previously.

A straightforward DATA step program should accomplish the task as you have described.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 39

Re: Scan string

The "K" functions can be used to manipulated strings where a character may take more than one byte. For instance, you could use KLENGTH to get the length of the string, then pick characters out of the string with KSUBSTR in a loop. A log snippet showing this is at the bottom of this post.

Jason

[pre]
19 data _null_;
20 text = 'abcdef';
21 do i = 1 to klength(text);
22 c = ksubstr(text, i, 1);
23 put c;
24 end;
25 run;

a
b
c
d
e
f
[/pre]
Ask a Question
Discussion stats
  • 4 replies
  • 151 views
  • 0 likes
  • 3 in conversation