BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Annie_Fréchette
Obsidian | Level 7

Hi! I would like to delete some lines from my data. See the print screen for an overview.

I want to remove the lines from the cows who have a chain_number starting with an "N". How can I ask this to SAS?

 

Thanks!

 

Annie_Fréchette_0-1594989099500.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So I'm pretty sure my original code works. Did you leave out the colon between = and 'N' ? It's easy to overlook.

 

 if you see an "N" no matter where you see it then delete?

 

if find(chain_number,'N')>0 then delete;
--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26
if left(chain_number)=:'N' then delete;
--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

Do I need to sort by chain_number first?

 

Thanks,

PaigeMiller
Diamond | Level 26

@Annie_Fréchette wrote:

Do I need to sort by chain_number first?


No.

--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

Hi, when I used the code it changed nothing so I have tried

data f6r;
set f6;
if first(chain_number)='N' then delete;
run;

first instead of left, and it worked!

 

But as I explore my data, I see that sometimes the N is after a space or at the end of the number. Can we ask: if you see an "N" no matter where you see it then delete?

 

Thanks

PaigeMiller
Diamond | Level 26

So I'm pretty sure my original code works. Did you leave out the colon between = and 'N' ? It's easy to overlook.

 

 if you see an "N" no matter where you see it then delete?

 

if find(chain_number,'N')>0 then delete;
--
Paige Miller
Annie_Fréchette
Obsidian | Level 7

Thanks, with this line everything is ok!

novinosrin
Tourmaline | Level 20
where first(strip(chain_number)) ne 'N';

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 785 views
  • 0 likes
  • 3 in conversation