Hello:
I would like to find 'P' letter in the first position in my dataset 'ID' column. I would like to use Proc SQL, not data step. Is there a way to do that? Thank you.
For example, my ID column is list:
1. PCR00026
2. NCR00025
3. PCR00027
4. NCR00033
5. NCR00055
Therefore, I would like to find the ID #1 and ID#3.
proc sql;
create table Want as
select ID
from test
where ID....
order by id;
DATA A;
INPUT ID $;
CARDS;
PCR00026
NCR00025
PCR00027
NCR00033
NCR00055
;
RUN;
PROC SQL;
CREATE TABLE b AS
SELECT * FROM a
WHERE SUBSTR(ID,1,1)='P'
oRDER BY id;
QUIT;
PROC PRINT;
RUN;
DATA A;
INPUT ID $;
CARDS;
PCR00026
NCR00025
PCR00027
NCR00033
NCR00055
;
RUN;
PROC SQL;
CREATE TABLE b AS
SELECT * FROM a
WHERE SUBSTR(ID,1,1)='P'
oRDER BY id;
QUIT;
PROC PRINT;
RUN;
Hi,
proc sql;
select * from test
where lower(id) like 'p%';
quit;
Regards,
Anushree
Thank you so much!
The EQT operator is another option:
where ID eqt 'P'
That is cool! How to express not equal?
@ybz12003 wrote:
That is cool! How to express not equal?
The negative operator corresponding to EQT is the NET operator ("not equal to truncated strings"; see the table I linked in the other post). So, for example, with where name net 'Ja' you could select all names from SASHELP.CLASS not starting with "Ja".
The first() function is the appropriate function to use here.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.