<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: set variable value to global constant in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27162#M4925</link>
    <description>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.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
There's some simple examples on the help pages &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm&lt;/A&gt;.&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps!</description>
    <pubDate>Thu, 10 Mar 2011 22:08:24 GMT</pubDate>
    <dc:creator>DF</dc:creator>
    <dc:date>2011-03-10T22:08:24Z</dc:date>
    <item>
      <title>set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27161#M4924</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
     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.  &lt;BR /&gt;
&lt;BR /&gt;
     What I have done:&lt;BR /&gt;
&lt;BR /&gt;
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.  &lt;BR /&gt;
&lt;BR /&gt;
2) I need to use these values in a new data set that looks somewhat like&lt;BR /&gt;
&lt;BR /&gt;
data blah.blah;&lt;BR /&gt;
set different.data;&lt;BR /&gt;
&lt;BR /&gt;
      do  i = MIN to MAX;&lt;BR /&gt;
&lt;BR /&gt;
etc;&lt;BR /&gt;
&lt;BR /&gt;
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?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Jennifer</description>
      <pubDate>Thu, 10 Mar 2011 22:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27161#M4924</guid>
      <dc:creator>Jennifer_Atlas</dc:creator>
      <dc:date>2011-03-10T22:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27162#M4925</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
There's some simple examples on the help pages &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm&lt;/A&gt;.&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps!</description>
      <pubDate>Thu, 10 Mar 2011 22:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27162#M4925</guid>
      <dc:creator>DF</dc:creator>
      <dc:date>2011-03-10T22:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27163#M4926</link>
      <description>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.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
macro variable introduction site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro variable scope symput site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
resolving macro variables in code site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro variable debugging site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro variable symbol resolution site:sas.com</description>
      <pubDate>Thu, 10 Mar 2011 23:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27163#M4926</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-03-10T23:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27164#M4927</link>
      <description>Thanks for your help.  I've been trying to get SYMPUT to work but the language is a little confusing.  Here's what finally worked:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*  GET MIN &amp;amp; MAX  */&lt;BR /&gt;
proc means data=gds1 noprint;&lt;BR /&gt;
	output out=fix1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* PULL OUT MIN*/&lt;BR /&gt;
&lt;BR /&gt;
data fix2a;&lt;BR /&gt;
set fix1;&lt;BR /&gt;
	if _STAT_ = 'MIN' then bot0 = &amp;amp;var1;&lt;BR /&gt;
	if bot0 = . then delete;&lt;BR /&gt;
CALL SYMPUT('bot1', PUT(bot0, 3.));&lt;BR /&gt;
	keep bot0;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put &amp;amp;bot1;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* PULL OUT MAX*/&lt;BR /&gt;
data fix2b;&lt;BR /&gt;
set fix1;&lt;BR /&gt;
	if _STAT_ = 'MAX' then top0 = &amp;amp;var1;&lt;BR /&gt;
	if top0 = . then delete;&lt;BR /&gt;
&lt;BR /&gt;
CALL SYMPUT('top1', PUT(top0, 3.));&lt;BR /&gt;
	keep top0;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put &amp;amp;top1;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*  I'm sure there are some redundancies in this but I was trying to break it down to each little step to figure out what was going wrong.  */</description>
      <pubDate>Mon, 14 Mar 2011 18:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27164#M4927</guid>
      <dc:creator>Jennifer_Atlas</dc:creator>
      <dc:date>2011-03-14T18:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27165#M4928</link>
      <description>Suggest you share your SAS log output with all code revealed for useful feedback - also you have a macro var reference &amp;amp;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).&lt;BR /&gt;
&lt;BR /&gt;
And, for desk-checking your flow, here's a SAS statement to turn on diagnostics:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */ ;&lt;BR /&gt;
&lt;BR /&gt;
Also, for DATA step analysis / diagnostics, code this statement at various points (must be at SAS 9 to use PUTLOG):&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG / _all_;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 14 Mar 2011 19:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27165#M4928</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-03-14T19:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27166#M4929</link>
      <description>PROC SQL can also create macro variables.  I suggest that you peruse the PROC SQL documentation for details.  Below is a rough code example;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select min(bot0) as min , max(bot0 ) as max&lt;BR /&gt;
  from gds1;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data fix2b;&lt;BR /&gt;
  set fix1;&lt;BR /&gt;
&lt;BR /&gt;
 do i=&amp;amp;min to &amp;amp;max;&lt;BR /&gt;
endd;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I would verify that the min and max are integers&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Darryl</description>
      <pubDate>Mon, 14 Mar 2011 19:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27166#M4929</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-03-14T19:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: set variable value to global constant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27167#M4930</link>
      <description>@Jennifer:&lt;BR /&gt;&lt;BR /&gt;
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:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;proc&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;summary&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;=sashelp.class;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;age;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;=stat(drop=_:)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;min&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;(age)=minAge&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;max&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;(age)=maxAge;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;_n_&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;1&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;stat;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;minAge&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;to&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;maxAge;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;age=;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;stop&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;on&amp;nbsp;log&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=11&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=12&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=13&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=14&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=15&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;age=16&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/SPAN&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 Mar 2011 19:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-variable-value-to-global-constant/m-p/27167#M4930</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-03-14T19:42:22Z</dc:date>
    </item>
  </channel>
</rss>

