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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1034 views
  • 0 likes
  • 3 in conversation