BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Naveen45
Fluorite | Level 6
I want to segregate the data into 5 datasets in following way. dataset1- All the data where type variable is numeric dataset2 - All the data where type variable is capital letter dataset3- All the data where type variable is small letter dataset4- All the data where type variable is both capital and small but starts with capital letter. dataset5- All the data where type variable is both capital and small but starts with small letter.
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data test2;
input type$ desp$;
datalines;
Dj dfg
jD dfg
DD dfg
dd dfg
J jam
v var
g gas
A apple
C cat
h hat
Aj rrr
Aa fff
1 222
2 333
;

data set1 set2 set3 set4 set5;
set test2;
if anydigit(type)>0 and anyalpha(type)=0 then output set1 ;
else if anyalpha(type)>0 and anydigit(type)=0 and  anylower(type)=0 then output set2;
else if anyalpha(type)>0 and anydigit(type)=0 and  anyupper(type)=0 then output set3;
if anyupper(first(type))>0 and anylower(type)>0 then output set4;
else if anylower(first(type))>0 and anyupper(type)>0 then output set5;
run;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
data test2;
input type$ desp$;
datalines;
Dj dfg
jD dfg
DD dfg
dd dfg
J jam
v var
g gas
A apple
C cat
h hat
Aj rrr
Aa fff
1 222
2 333
;

data set1 set2 set3 set4 set5;
set test2;
if anydigit(type)>0 and anyalpha(type)=0 then output set1 ;
else if anyalpha(type)>0 and anydigit(type)=0 and  anylower(type)=0 then output set2;
else if anyalpha(type)>0 and anydigit(type)=0 and  anyupper(type)=0 then output set3;
if anyupper(first(type))>0 and anylower(type)>0 then output set4;
else if anylower(first(type))>0 and anyupper(type)>0 then output set5;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 882 views
  • 1 like
  • 2 in conversation