@mandan414:
1. First, you have a data type conflict, as it follows from your code that either (a) myvariable is numeric but you're comparing it to character values or (b) it is character but you want to assign a numeric value 0/1 to it. Either way, you'll get a bunch of type conversion notes in the log. To avoid them, in case (a) convert it to $ on input as put(myvariable,3.) and use this expression instead of myvariable in the IF clause; or in case (b) assign "0"/"1" instead of 0/1. Better yet, use a different, new, variable to create your Boolean flag.
2. Second, if you just don't like tedious hard coding, you can shorten your list notation like so:
if "A10" <= myvariable <= "A14"
3. Third, it's still hard coding, albeit less tedious. Not sure why you mention "macro" in the context but let's assume that you mean using macro variables to parameterize your code in order to avoid hard coding altogether. The latter is a good idea; but using macro variables for the purpose is, generally speaking, not, especially since all you need is a set of lookup values. It's much better and more robust and scalable to store them in a file external to the program and make the program read it and create a lookup table of your choice.
@novinosrin showed you one way to do it using an informat (considering point #1, you may actually need a format, depending on the actual data type of myvariabe). However, if you simply store the lookup values in a SAS data set (which you can edit without touching the code) and make the program read it to create an in/format by composing a CNTLIN= data set and feeding it into proc FORMAT; then you can use the resulting in/format just like @novinosrin showed.
However, the advantages of such an approach don't end here because by having the control data set with the lookup values you can use it with any lookup method you may fancy, for example:
use it as one side in an SQL join
index it and use the index as a lookup facility via SET ... KEY=
load a hash table in the DATA step where you need to do the lookup
load a hash table into a function using proc FCMP and then use the function to do the lookup in any subsequent step, including in the WHERE clause
etc.
And of course you can use the control table to populate a bunch of macro variables, if need be, via SYMPUTX in the DATA step or the INTO clause via proc SQL. It avoids hard coding, too, because in your lookup code you'll have only macro variable references rather than their values; but given all the possibilities listed above, I'd wonder why one would opt for such a cumbersome route.
Kind regards
Paul D.
... View more