```Date: Thu, 25 Jul 2002 15:24:30 -0600 Reply-To: Kenneth Moody Sender: "SAS(r) Discussion" From: Kenneth Moody Subject: Re: Double Assignment Content-Type: text/plain; charset=us-ascii Jess, Evaluation of expressions is covered in the SAS Language Reference: Concepts manual in Chapter 12. You've asked about a special case, because var3 is surrounded by two comparison operations; it's evaluated as: var1 = (var2=var3) and (var3 = 7); In your case var2 is missing, so the evaluation is (.=6) and (6=7), which is 0 and 0, so var1 = 0; The left most equal sign is an assignment operator, all of the others are comparison operators. The special case of a quantity surrounded by two comparison operators is what allows us to write expressions like '1jan2001'd le date_var le '31dec2001'd to test whether a quantity is within a range. Ken Moody First Health, Metrics Department Voice: 916-374-3924 EMail: KennethMoody@firsthealth.com >>> "Balint, Jess" 07/25/02 01:49PM >>> Actually I was talking about: var1=var2=var3=7; Where does SAS decide to put the parenthesis? Hence: data _NULL_; var3 = 6; var1=var2=var3=7; put var1 var2 var3; run; If or not var3 = 7, var2 is missing and var1 is 0. How is it evaluated? Why didn't they use the good old '?:' conditional operator? -----Original Message----- From: Ian Whitlock [mailto:WHITLOI1@WESTAT.com] Sent: Thursday, July 25, 2002 4:53 PM To: 'Balint, Jess'; SAS-L@LISTSERV.UGA.EDU Subject: RE: Double Assignment Jess, var2=var3=7 is short for (var2 = var3) and (var3 = 7) I see no reason why VAR2 should always be missing, but if it is then the result is 0 because a logical consequence (transitivity of equality) of the above expression is that var2 = 7 and this is never true when VAR2 is missing. Never trust what a programmer, or anyone else, tells you. Test it, decide for yourself, and be prepared to revise your opinion when more data is available to you. Of course even if you find that every example you consider leads to the truth of the statement you might wonder if SAS would give the same results tomorrow. If that is true it is time to take up another language or occupation. (However, note there are exceptions which may be allowed. Remember the result of some code can depend on the data, the operating system, the environment (both the out of disk space variety and magnets) as well as the language.) However you must also understand things like (run under winows 98 SAS 8.2) 1602 data _null_ ; 1603 x = 7 ; 1604 y = 7 + 4.44e-16 ; 1605 z = x = y ; 1606 put z = ; 1607 run ; z=1 The search for truth will always depend on what facts you find and your theoretical model of how to understand those facts. IanWhitlock@westat.com -----Original Message----- From: Balint, Jess [mailto:JBalint@ALLDATA.NET] Sent: Thursday, July 25, 2002 3:48 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Double Assignment How exactly would that work out? var2 is always missing?!? -----Original Message----- From: Sigurd Hermansen [mailto:HERMANS1@WESTAT.COM] Sent: Thursday, July 25, 2002 3:41 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Double Assignment I would not trust a programmer who leaves out the parentheses. What rules of operator precedence apply in multiple assignments across the same operator? Try to explain how SAS will evaluate var1=var2=var3=7; to someone other than a committed (or soon to be) SAS programmer! Sig -----Original Message----- From: Jack Hamilton [mailto:JackHamilton@FIRSTHEALTH.COM] Sent: Thursday, July 25, 2002 3:22 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Double Assignment Do you mean you have a hard time trusting this, i.e., that it will produce the answer of 0 or 1 correctly, or that you have a hard time believing that that's what the statement means? Why don't you trust or believe it? Has something happened to make you think it doesn't work that way? Will it help if you think of it as var = (var1 = 7) ? -- JackHamilton@FirstHealth.com Manager, Technical Development METRICS Department, First Health West Sacramento, California USA >>> "Balint, Jess" 07/25/2002 11:54 AM >>> Hello all. I have seen people here write code like "var2 = var1 = 7". From what they say var2 = 1 if var1 = 7 and var2 = 0 otherwise. I have a hard time trusting this. Is it correct though? Thanks. Jess ```

Back to: Top of message | Previous page | Main SAS-L page