Help using Base SAS procedures

Reg:pattern of Obs

Reply
N/A
Posts: 0

Reg:pattern of Obs

HOW CAN I FIND THE PATTERN OF THE OBS;

DATA TEST;
INPUT NAME$;
CARDS;
TESTed12
No34
MAin78
RUN;

OUTPUT

NAME----------PATTERN
TESTed12 ----- AAAAaa99
No34---------- Aa99
MAin678------- AAaa99


AS for every character is should represent as 'A' and for small letter it shouls show as 'a'for number it should represent digit 9
SAS Employee
Posts: 160

Re: Reg:pattern of Obs

This is one way of doing it - you could also use regular expressions or Dataflux.

data pattern;
set TEST;
length pattern $25.;
do i=1 to length(name);
if anydigit(substr(name,i,1)) then substr(pattern,i,1)='9';
else if ANYLOWER (substr(name,i,1)) then substr(pattern,i,1)='a';
else if ANYUPPER (substr(name,i,1)) then substr(pattern,i,1)='A';
else substr(pattern,i,1)='_';
end;
run;
Super Contributor
Posts: 394

Re: Reg:pattern of Obs

This would be a good question for a "SAS programming" test of some sort. See http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002288677.htm for more information about using regular expressions in a DATA step.
[pre]
data _null_;
if _n_ = 1 then do;
retain upper lower digit;
upper = prxparse('s/[A-Z]/A/');
lower = prxparse('s/[a-z]/a/');
digit = prxparse('s/\d/9/');
end;
input text $8.;
call prxchange(upper, -1, text);
call prxchange(lower, -1, text);
call prxchange(digit, -1, text);
put text;
datalines;
TESTed12
No34
MAin678
;;;;
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 107 views
  • 0 likes
  • 3 in conversation