```Date: Wed, 24 May 2000 08:39:41 -0400 Reply-To: Howard Schreier Sender: "SAS(r) Discussion" From: Howard Schreier Subject: Re: If Then Single ? I believe that If x22 = www then y32 = 'NA' and Y100 = 'wa'; is interpreted as If x22 = www then y32 = ('NA' and (Y100 = 'wa')); In other words, a comparison, then a boolean operation (involving implicit type conversion), then an assignment. There should be notes in the log about uninitialized variables and type conversions. On Wed, 24 May 2000 09:30:35 GMT, dkb@CIX.COMPULINK.CO.UK wrote: >Paula D asks: > >> I know for fact that this does not work: >> >> If x22 = www then y32 = 'NA' and Y100 = 'wa'; >> >> where x22 is a field read from original CSV data set and Y32 and y100 are >> new variables. If 'if-then' is used to generate new variables, as I wanted, >> I have to do it one new variable a time. Otherwise, once x22 is evaluated >> once, either 1 or 0 is assigned to x22 changing it from character to >> numeric, screwing up the whole thing. >> >> Now my question is: why single only? what is the merit for doing that? Any >> more efficient way to generate new variables conditionally like this? >> >> Paula D > >Paula, > >1) Your suggested syntax would mean that the meaning of the word "AND" should >change depending on whereabouts in an expression it appears. >Currently it's just a logical operator; when you code the expression >y32 = 'NA' and Y100 = 'wa' >you are directing SAS to compare the contents of two variables to two literals >and then return 0 or 1 depending on the results of the comparisons. >Your suggestion is that under certain conditions this expression should direct >SAS to instead overwrite the contents of the two variables with the specified >literals. The merit you ask for is consistency. I think making the behaviour >of "AND" context-dependent like that would be undesirable. I'm curious - do >you normally use another language that does behave like that? > >2) The syntax of if - then is simply >if (condition) then (statement); >The (statement) can be any valid SAS statement, in particular a DO, so you can >code >If x22 = www then do; > y32 = 'NA'; > Y100 = 'wa'; >end; > > >Kind regards, > >Dave >. ```

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