DATA Step, Macro, Functions and more

How to delete specific numbers in oberservations

Reply
Contributor
Posts: 21

How to delete specific numbers in oberservations

Hi,

 

My data looks like this. I need to figure out how to delete an observation when it contains specific numbers in the variable RES_ACC_RES_FKEY_LIST.

 

Currently in my code I have

if RES_ACC_RES_FKEY_LIST='55' then delete;

but that does not seem to delete any observations.

 

Thank you for your help!

 

Super User
Posts: 23,224

Re: How to delete specific numbers in oberservations

Assuming its the last column in your screenshot, It looks like it's pipe delimited, so you need to have an exact match. From the screenshot shown no records would match 55. 

 

Assuming you're looking for records that have only 55, I suspect it's actually entered as '|55|'. 

Or if you're searching the list that's a different question and you should use INDEX/INDEXW or FIND/FINDW as appropriate.

 

I'm assuming a lot here...the exact code depends on the details.


@dlazer1 wrote:

Hi,

 

My data looks like this. I need to figure out how to delete an observation when it contains specific numbers in the variable RES_ACC_RES_FKEY_LIST.

 

Currently in my code I have

if RES_ACC_RES_FKEY_LIST='55' then delete;

but that does not seem to delete any observations.

 

Thank you for your help!

 


 

 

 

 

Respected Advisor
Posts: 2,796

Re: How to delete specific numbers in oberservations

[ Edited ]

Some of us won't open Microsoft Office documents, as they can be a security risk. You could show us part of your data as plain text in the actual message.

 

Anyway, as a guess, not seeing your data, if this doesn't work for you,

if RES_ACC_RES_FKEY_LIST='55' then delete;

then perhaps you might want to try

 

if find(res_acc_res_fkey_list,'55')>0 then delete;

 

--
Paige Miller
Super User
Posts: 13,283

Re: How to delete specific numbers in oberservations

Best is to start by providing an example of your data set. A picture or a table in a word document is not a SAS data set.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Ask a Question
Discussion stats
  • 3 replies
  • 78 views
  • 0 likes
  • 4 in conversation