BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jkinkade7
Calcite | Level 5

Apologies if I've put this in the wrong place, I'm completely new here but this seemed like the best forum based on the introductory channels' description.

 

Basically I am working on a class assignment and trying to create two different subsets of my data: one with only renters included and one with only homeowner's included. My code that's not functioning is below, and I can supply more if needed:

 

data RentersData;
	set FullData2;
	delete if RENTGRS=0;
run;

Basically I am trying to drop all observations from my data where gross rent payments (RENTGRS) are equal to 0 so that only renters are included. However, I keep getting an error message that says ERROR 79-322: Expecting a ;. 

 

Adding a screenshot below of the error message just in case there's any important detail I may have ignored

jkinkade7_0-1679875143744.png

 

I hope this is descriptive enough, I can provide additional info if necessary. Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
Modeller
Fluorite | Level 6

I believe you need to switch your "delete" & "if" statements around. See solution 1 below.

 

I have included solutions 2 &3 that achieve the same result using different methods as well.

 

Modeller_0-1679876190710.png

View solution in original post

3 REPLIES 3
Modeller
Fluorite | Level 6

I believe you need to switch your "delete" & "if" statements around. See solution 1 below.

 

I have included solutions 2 &3 that achieve the same result using different methods as well.

 

Modeller_0-1679876190710.png

jkinkade7
Calcite | Level 5

Thank you so much, Solution 1 worked perfectly. I appreciate the additional solution approaches as well because they look like a cleaner solution than what I was opting for, I think they will help me a lot in the future

Tom
Super User Tom
Super User

The DELETE statement does not allow any other text.  That is why SAS says you are missing a semicolon.  Your text looks like it was meant to be two statements.  A DELETE statement and subsetting IF statement.

delete;
if RENTGRS=0;

But that would delete every observation.

 

If you want to conditionally execute the DELETE statement then you can use an IF/THEN statement and code the DELETE statement as the statement to execute when the condition is true.

if RENTGRS=0 then delete;

If instead you want to use a subsetting IF statement you will need to reverse the logic of condition since now you want to specify the condition for when to NOT delete the observation.

if RENTGRS ne 0;

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 200 views
  • 2 likes
  • 3 in conversation