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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 606 views
  • 0 likes
  • 3 in conversation