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

Hello, 

I am a new SAS user and am stumped on why my 'if then delete' statement is not working for the 'primary_site_labeled' variable.

Please see the attached PDF of my code.

I had the same problem with the 'age_recode_with_1_year_olds' variable, until I wrote a separate statement for each value that I wanted to be deleted, but I obviously don't want to write out every value for the 'primary_site_labeled' variable.

I also tried writing two statements (one with '<180' and the other with '>209') but then it said that there were no observations in my data set (there should still be hundreds of thousands).

Thanks,

Melody

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Ok, did the typing now. But please post next time code using the running man.

data save.new2;
  set save.new;
  if age_recode_with_1_year_olds in (0,1,2,3,4,29) then delete;
  else if 0<=primary_site_labeled<=179 then delete;
  else if 201<=primary_site_labeled<=809 then delete;
run;

You could also write it this way:

data save.new2;
  set save.new;
  if age_recode_with_1_year_olds in (0,1,2,3,4,29) 
    or 0<=primary_site_labeled<=179 
    or 201<=primary_site_labeled<=809 then
    delete;
run;

 

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

Welcome to the SAS Communities.

Can you please post your code using the running man icon  

Capture.JPG

This gives us access to your code as properly formatted text so we can provide the amended code as answer without having to re-type it from some PDF. It's an easy fix.

Patrick
Opal | Level 21

Ok, did the typing now. But please post next time code using the running man.

data save.new2;
  set save.new;
  if age_recode_with_1_year_olds in (0,1,2,3,4,29) then delete;
  else if 0<=primary_site_labeled<=179 then delete;
  else if 201<=primary_site_labeled<=809 then delete;
run;

You could also write it this way:

data save.new2;
  set save.new;
  if age_recode_with_1_year_olds in (0,1,2,3,4,29) 
    or 0<=primary_site_labeled<=179 
    or 201<=primary_site_labeled<=809 then
    delete;
run;

 

mkit8
Fluorite | Level 6

Thank you so much, Patrick! That works perfectly. I appreciate your help.

I'll make sure to share my code properly next time.

 

Melody

Patrick
Opal | Level 21

Hi Melody,

Glad that it helped. And now the last step for how these SAS Forums work: If an answer resolves your problem then accept it as solution. This not only shows everybody else that this question is answered, it also helps people searching  existing discussions for answers to quickly get to a post which provides a solution.

Cheers,

Patrick

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 678 views
  • 1 like
  • 2 in conversation