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
AbB1 | 4 | 4 |
aaaa | 5 | 4 |
Bcc | 4 | 3 |
Cdd | 4 | 3 |
Why is Notalphap not 0 for Seq = aaaa, Bcc, or Cdd?
Thanks.
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;
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));
For any text that needs to be posted as-is (log, textual data, results), use this button:
Use the "little running man" right next to it for SAS code.
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;
Dear SASKiwi, Thanks a lot.
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.
Dear Tom, Thank you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.