I am trying to extract a value from a variable and set it as a global constant that I can call in a different data set. What I have right now is resolving to the variable names and not the constant values that I need. I need to be able to use this value in a do loop.
What I have done:
1) I have extracted the minimum and maximum values for a variable in proc means and created a data set for each of these values.
2) I need to use these values in a new data set that looks somewhat like
do i = MIN to MAX;
I need to be able to pull those min and max values out as constants so that I can use them in this new dataset. Does anyone know how I can do this?
One option would be to use a SAS Macro variable to store your values. This would all you to extract your values in one section of your code, store the min/max values in macros, and then refer to those later in your code.
The symbol generator would replace references to the macros in your code with their saved values, after which your code would be compiled and ran.
If you are wanting to capture a SAS variable value and make it available in another DATA step (or somewhere in your current SAS session), you will need to look at using CALL SYMPUT. Then, with the SAS global macro variable assigned, you can reference that macro variable elsewhere in your current SAS session. It is important to learn and understand how SAS macro variables are accessed, assigned, and referenced in the different parts of the SAS system, particularly SAS macro based programs, SAS DATA step variables (through an assignment or RETAIN statement), and as a constant/literal value in a SAS language expression / statement.
Suggested Google advanced search arguments, this topic / post:
Suggest you share your SAS log output with all code revealed for useful feedback - also you have a macro var reference &var1 -- we don't see that variable assigned anywhere? Is this PROC/DATA step code called from within a macro - or how/where is macro variable VAR1 assigned? Really need to see your log - also tell more about your outward symptom, if unexpected (and what's expected too).
And, for desk-checking your flow, here's a SAS statement to turn on diagnostics:
I am not sure if you need to pass you statistics to macro variables to be used in another data step. In general, it is better to use little macros; and to avoid the global macro variables altogether. There are inevitable losses of precision involved when you convert numeric values to characters and back. Not using global macro vars, thus, your results can be accurate. In addition, the code gets (much) simpler without global macro vars in many cases. For instance, you can do something like below: