BookmarkSubscribeRSS Feed
dentrix
Calcite | Level 5

a)

data ;

if a >= b then c=0;;

else c=-1;

run;

 

b)

data ;

if a >= b then label dob="date of birth";

else label dob="date of death";

run;

3 REPLIES 3
ballardw
Super User

Did you try running any of the code to see if you get error messages?

 

Where to initial values for A and B come from in the first data step?

Similar in the second plus the LABEL statement is not conditional and depending on what was intended there could be several logic errors other than the syntax issues assignment and such.

PGStats
Opal | Level 21

These questions are meant to make you think by yourself, not to test your ability to survey others. What do YOU understand about these codes?

PG
yabwon
Amethyst | Level 16

Hi,

 

Regardless the fact that you didn't initialized variables, as @ballardw pointed out, reasons seems to be as follows:

 

a) - double semicolon after "if-then" part - it should be 1 (one) semicolon there, with two(;;) sas thinks that you have an empty statement there (second semicolon) and it throws an syntax error on the "else" part 

 

b)  - as @ballardw pointed out, Label is not execution time statement but compilation time one. Try to test following code (which from the execution time point of view reduces to "empty" do-end block):

data _null_;
  if a >= b then do; label dob="date of birth"; end;
            else do; label dob="date of death"; end;
run;

all the best

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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

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
  • 3 replies
  • 1316 views
  • 2 likes
  • 4 in conversation