BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
GertNissen
Barite | Level 11
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;
Tim_SAS
Barite | Level 11
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]

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1087 views
  • 0 likes
  • 3 in conversation