BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

I need to know the observations where var1 starts with a number and var2 starts with a letter. Can someone please help me with the code.

 

Here is my sample data.

 

Thanks,

 

 

DATA have;
INPUT var1 $10. var2 $10.;
DATALINES;
A153C254	BBF
3 Cuort		5nng
4hhg		r4ee5
B124 		CC8	
0564		1DD	
15D48 		FF	 
na 3N2	
w853	    55K
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What do you expect the result to look like when digit or letter is found in the first position?

The functions ANYDIGIT, ANYLOWER or ANYUPPER may help depending on your desired output.

 

If ANYDIGIT(var1) = 1 then var1 starts with a digit for example.

View solution in original post

3 REPLIES 3
ballardw
Super User

What do you expect the result to look like when digit or letter is found in the first position?

The functions ANYDIGIT, ANYLOWER or ANYUPPER may help depending on your desired output.

 

If ANYDIGIT(var1) = 1 then var1 starts with a digit for example.

mlogan
Lapis Lazuli | Level 10
Thanks, it worked for me.
PeterClemmensen
Tourmaline | Level 20

Alternatively..

 

DATA have;
INPUT var1 $ 1-8 var2 $ 10-14;
DATALINES;
A153C254 BBF  
3 Cuort  5nng 
4hhg     r4ee5
B124     CC8  
0564     1DD  
15D48    FF   
na 3N2        
w853     55K  
;

data want;
    set have;
    if prxmatch('/^\d.*/', var1) & 
       prxmatch('/^[a-zA-Z].*/', var2);
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 5209 views
  • 2 likes
  • 3 in conversation