BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nietzsche
Lapis Lazuli | Level 10

so SAS is able to run an IF statement without THEN statement and this is called subsetting.

But if I follow that with an ELSE statement, SAS is still able run correctly as shown by the code below and the result attached.

data merged nomatch;
	merge cert.patdat (in=inpat rename=(date=BirthDate))
			cert.visit (in=invisit rename=(date=VisitDate));
by id;
if inpat=1 and invisit=1;
else output nomatch;
run;

proc print data=merged;run;
proc print data=nomatch;run;

Nietzsche_0-1668817682185.png

 

so why is it that when I look at the log, there is an error No matching IF-THEN clause if everything was ran okay?

Nietzsche_1-1668817722728.png

 

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
1 ACCEPTED SOLUTION
6 REPLIES 6
Tom
Super User Tom
Super User

I don't see any THEN in your code.

So you have an ELSE without any IF/THEN. Just like the error message says.

 

Note that a subsetting IF is a completely different statement than and IF/THEN statement.  And there is no way an ELSE statement makes any sense with a subsetting IF.  If the condition is false none of the code after that runs. So the ELSE can never happen.

 

Click to see corrected code:

Spoiler
data merged nomatch;
  merge cert.patdat (in=inpat rename=(date=BirthDate))
    cert.visit (in=invisit rename=(date=VisitDate))
  ;
  by id;
  if inpat=1 and invisit=1 then output merged;
  else output nomatch;
run;

 

Nietzsche
Lapis Lazuli | Level 10

so SAS still run fine despite the error?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
Tom
Super User Tom
Super User

The log will tell you if it ran.

But the logic is wrong so I doubt it did what you wanted if it did run.

Nietzsche
Lapis Lazuli | Level 10

no worries, I will stick to IF THEN ELSE standard.

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
Nietzsche
Lapis Lazuli | Level 10

omg what a rookie mistake I made.

 

is there a way to clear the result every time I ran a new code in the same tab in SAS studio?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1997 views
  • 4 likes
  • 3 in conversation