Here we are combining %if with if directly - and on top of things, we're actually getting in the middle of the SAS statement. Now we add one more step - we add a low and high bound. We're using %do to control our imaginary typer of code (deciding what gets placed in the data step), and we're using if as an actual SAS program statement, something we want actually typed into our program. If &L LE age LE &H then agerange = "&L.-&H." Then, on top of that, we add a layer of looping to make using the macro easier: %macro agerange_bytwo(low,high) If &low LE age LE &high then agerange = "&low.-&high." You could type %macro agerange(low,high) If 15 LE age LE 16 then agerange = '15-16' If 13 LE age LE 14 then agerange = '13-14' If 11 LE age LE 12 then agerange = '11-12' SAS macros are effectively the same thing. It's not actually doing any of the opening and running - it's just taking a list of commands - open, load file, run file - and executing them one after another. Keyboard macros are an example of this - setting "Ctrl+Shift+A" to load an autoexec and run it, say, more efficiently than ctrl+o, find file, open, hit run. It is not intended to interface with data or even to do most of your work for you in most cases and being 'in a macro' has nothing to do with whether you're using %IF or IF.įundamentally, macros are intended to be ways to take a bunch of complicated things that you do regularly and do them with a few keystrokes rather than writing them out every time. Macro programming in SAS exists for the purpose of writing SAS language statements in a more efficient manner than you could write them out by hand. So my question is: Is it possible to do what I want inside a macro? If so, is my attempt close to the solution or do I need to radically change it? I apologize if this is a simple question or if I am missing a crucial aspect of SAS macro programming (likely to be the case), but I have searched and found no other solution for what I want to do. I have tried this with the missing function but it also did not work. The condition was: nmiss(of ret1Īpparently the %IF statement in a macro does not evaluate the nmiss or cmiss functions. ERROR: A character operand was found in the %EVAL function or %IF condition If I use it outside a Macro, it works very well, but inside a macro it gives me the following error and I do not know how to go around it. %if nmiss(of ret1 - ret2) + cmiss(of ret1 - ret2) > 0 %then %if nmiss(of ret1 - ret2) + cmiss(of ret1 - ret2) > 1 %then merged datasetįor this I created this data step. My objective is to delete the records where ret1 and ret2 are missing and to have a variable OBS = 1 in all records where ret1 and ret2 are not missing. This dataset looks something like this (simplified): merged dataset I have a certain macro which, inside of it, creates a data set called merged from a PROC SQL. Is there an alternative?įollowing a previous question, I ran into an issue. Edit: I read further on the subject of macro programming and apparently, if the macro is precomplied, then none of its statments may depend on the data contents, hence this way of doing it is no good.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |