DATA Step, Macro, Functions and more

how do i check all the bytes are same in a variable

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

how do i check all the bytes are same in a variable

Hi 

 

I would like to check a field whether all the bytes are having same values.

Eg. I need to check  field EMP_ID which is 9bytes

IF EMP_ID in ('111111111','222222222','333333333',...,'999999999') then 

message = 'invalid employee id';

 

how to replicate the above scenario in an optimal way.

 

Thanks in advance 


Accepted Solutions
Solution
a month ago
Super User
Posts: 10,280

Re: how do i check all the bytes are same in a variable

Posted in reply to elangooff1

How about

if compress(emp_id,substr(emp_id,1,1)) ="" then .....;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
a month ago
Super User
Posts: 10,280

Re: how do i check all the bytes are same in a variable

Posted in reply to elangooff1

How about

if compress(emp_id,substr(emp_id,1,1)) ="" then .....;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 2

Re: how do i check all the bytes are same in a variable

Posted in reply to KurtBremser

Thanks Smiley Happy this works perfectly

Respected Advisor
Posts: 4,737

Re: how do i check all the bytes are same in a variable

Posted in reply to elangooff1

@elangooff1

You'll probably need some extra treatment for missing source strings.

 

Here some additional coding options.

data sample;
  infile datalines truncover;
  input instr $char16.;
  flg1 =prxmatch('/^(\d)\1*$/o',strip(instr));
  flg2 =prxmatch('/^(\d)\1*$/o',compress(instr));
  flg3 = compress(instr,substr(instr,1,1)) eq " ";
  datalines;
11111111
2222
11111121
333 333
  444 444
  
 555 6 55
 777 7 77
aaaaaaa
;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 74 views
  • 1 like
  • 3 in conversation