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;
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?
As the log tells you, no. Syntax errors stop the compilation, so execution never happens.
If you find the resulting dataset, it's from an earlier execution that worked.
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:
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;
so SAS still run fine despite the error?
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.
no worries, I will stick to IF THEN ELSE standard.
As the log tells you, no. Syntax errors stop the compilation, so execution never happens.
If you find the resulting dataset, it's from an earlier execution that worked.
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?
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!
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.
Ready to level-up your skills? Choose your own adventure.