BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
yannlee
Fluorite | Level 6

DATA Tst;
INPUT Seq $;
Notalphap=NOTALPHA(Seq);
Seql=LENGTH(Seq);
DATALINES;
AbB1
aaaa
Bcc
Cdd
;
RUN;
PROC SQL;
SELECT Seq, Notalphap, Seql
FROM Tst;
QUIT;

I got 

Seq Notalphap Seql
AbB144
aaaa54
Bcc43
Cdd43

 

Why is Notalphap not 0 for Seq = aaaa, Bcc, or Cdd?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

The TRIM HAS to be nested inside NOTALPHA. It wont work as a separate statement as SAS will always pad with blank characters to the right of any non-blank characters.

DATA Tst;
INPUT Seq $;
Notalphap=NOTALPHA(trim(Seq));
Seql=LENGTH(Seq);
DATALINES;
AbB1
aaaa
Bcc
Cdd
;
RUN;
PROC SQL;
SELECT Seq, Notalphap, Seql
FROM Tst;
QUIT;

SASKiwi_0-1655872968964.png

 

View solution in original post

8 REPLIES 8
Reeza
Super User

Looks like it's finding those spaces at the end based on the length. Use TRIM() to remove the spaces and get the expected value back. 

I agree, not how I would expect the function to work. 

 

Notalphap=NOTALPHA(trim(Seq));
yannlee
Fluorite | Level 6
Dear Reeza,
Thank you so much.
However TRIM does not work. Please see below.
DATA TST;
INPUT Seq $;
SeqT=TRIM(Seq);
Notalphap=NOTALPHA(Seq);
NotalphaTp=NOTALPHA(SeqT);
Seql=LENGTH(Seq);
SeqTl=LENGTH(SeqT);
DATALINES;
AbB1
aaaa
Bcc
Cdd
;
RUN;
PROC SQL;
SELECT Seq, SeqT, Notalphap, NotalphaTp, Seql, SeqTl
FROM Tst;
QUIT;
I got
Seq SeqT Notalphap NotalphaTp Seql SeqTl
AbB1 AbB1 4 4 4 4
AbB1a AbB1a 4 4 5 5
aaaa aaaa 5 5 4 4
Bcc Bcc 4 4 3 3
Cdd Cdd 4 4 3 3

yannlee
Fluorite | Level 6
I am sorry that the table becomes disarranged after I post it here.
SASKiwi
PROC Star

The TRIM HAS to be nested inside NOTALPHA. It wont work as a separate statement as SAS will always pad with blank characters to the right of any non-blank characters.

DATA Tst;
INPUT Seq $;
Notalphap=NOTALPHA(trim(Seq));
Seql=LENGTH(Seq);
DATALINES;
AbB1
aaaa
Bcc
Cdd
;
RUN;
PROC SQL;
SELECT Seq, Notalphap, Seql
FROM Tst;
QUIT;

SASKiwi_0-1655872968964.png

 

yannlee
Fluorite | Level 6

Dear SASKiwi, Thanks a lot.

Tom
Super User Tom
Super User

Space is NOT an ALPHA character.

 

SAS stores characters strings as fixed length, padded with space.  Since you did NOT define the length of the variable SEQ before using it in the INPUT statement SAS had to GUESS how to define it so it defined it as length of $8.

 

Tom_0-1655865478039.png

 

yannlee
Fluorite | Level 6

Dear Tom, Thank you.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 850 views
  • 3 likes
  • 5 in conversation