BookmarkSubscribeRSS Feed
syk
Obsidian | Level 7 syk
Obsidian | Level 7

What am I doing wrong? The statement is exactly the same format from the documentations I've read and the DELETE statement should be blue but it's greyed out.

 

Capture.GIF

 

12 REPLIES 12
Tom
Super User Tom
Super User

What is the question? Are you really talking about what COLOR the text is in the program editor?

If you want to see if the code works, run it.

syk
Obsidian | Level 7 syk
Obsidian | Level 7

I've ran the code the delete statement is definitely not processing through, and as you can see from the captured image the delete statement is not even recognized as a sas statement.

Miracle
Barite | Level 11

By the way, your sum statement should be 

Total=sum(qtr1,qtr2,qtr3,qtr4);
Tom
Super User Tom
Super User
@syk wrote:

I've ran the code the delete statement is definitely not processing through, and as you can see from the captured image the delete statement is not even recognized as a sas statement.


You posted a photograph of an editor screen. The color coding that an editor does is just the editor's attempt to make your code look pretty. The editor does not actually contain the SAS parser/compiler or the SAS macro processor.

 

If you want to see whether the SAS code is correct you need to actually run the code.  

 

If you want to tell whether the DELETE statement ran we would need to see the LOG to see how many observations the data step read in and how many it wrote. We would also need to see the data since it could very well be that no obervations meet the IF condition so that the DELETE statement will never run.

 

If you had really typed something other than delete (perhaps de1ete) then you would have seen an error message in the SAS log that the statement was invalid.

syk
Obsidian | Level 7 syk
Obsidian | Level 7

I've tried both conditions for the IF statement to produce 50 observations (the question wanted 50) but when I ran it again with the counter-logic it produced 88 observations (initial number of observations) so the delete statement did not work. And no I did not spell delete incorrectly. And as you can see for some reason when the delete statement is within the IF statement it's not picked up by the compiler, but by itself it is..

Capture.GIF

Tom
Super User Tom
Super User

@syk wrote:

I've tried both conditions for the IF statement to produce 50 observations (the question wanted 50) but when I ran it again with the counter-logic it produced 88 observations (initial number of observations) so the delete statement did not work. And no I did not spell delete incorrectly.


That is a totally different question.

Why would you expect that running that data step would produce 50 observations?

There is nothing in the code that would do that. It might do that if there are exactly 50 observations that do NOT get deleted by that IF statement. But we would need to see the data.

 

Tom
Super User Tom
Super User

Ignore the colors. Look at the log. SAS will put an erorr message in the log is you ask it to run invalid code. Until you actually submit the code to run the editor is just an editor. It doesn't really know whether you are typing SAS code or your shopping list.

syk
Obsidian | Level 7 syk
Obsidian | Level 7

You're right the statement is really meaningless I was just simply showing the compiler is not picking up the delete statement, and the log had no errors. 

 

if Total>=50 and NumQtrs=4; <--- this statement produced 50 observations like the questioni wanted.

so shouldn't 

 

if Total<50 and NumQtrs^=4 then delete; 

 

produce 50 observations as well?

Tom
Super User Tom
Super User

@syk wrote:

You're right the statement is really meaningless I was just simply showing the compiler is not picking up the delete statement, and the log had no errors. 

 

if Total>=50 and NumQtrs=4; <--- this statement produced 50 observations like the questioni wanted.

so shouldn't 

 

if Total<50 and NumQtrs^=4 then delete; 

 

produce 50 observations as well?


No. Apply DeMorgan's law.  https://en.wikipedia.org/wiki/De_Morgan%27s_laws

NOT (A and B) is the same as (NOT A) or (NOT B).

Kurt_Bremser
Super User

DeMorgan is one of the foundations of programming. As soon as one touches the first composite condition, one does not only have to know DeMorgan's laws, one needs to internalize them to the point where the hands automatically type the correct conversion.

 

@syk: the coloring in the SAS enhanced editor is not complete; some keywords are not caught correctly. Follow my Maxims 4 and 2.

Reeza
Super User

 

if Total>=50 and NumQtrs=4; <--- this statement produced 50 observations like the questioni wanted.

so shouldn't 

 

if Total<50 and NumQtrs^=4 then delete; 

 

produce 50 observations as well?


No, you have two conditions joined by an AND so you theoretically have 4 different possibilities (2X2)

 

Total >= 50 and NumQtrs=4

Total < 50 and NumQtrs=4

Total >= 50 and NumQtrs^=4

Total < 50 and NumQtrs^=4

ballardw
Super User

If Total is missing then Total<50 is True.

If NumQtrs is missing then NumQtrs ^= 4 is True.

 

So if you have missing values for the selection variables you may have more or fewer results than you think you should.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 12 replies
  • 2985 views
  • 5 likes
  • 6 in conversation