<?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: Store numeric macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687486#M208709</link>
    <description>&lt;P&gt;While symput will work, symputx is the better choice.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 12:14:18 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2020-09-29T12:14:18Z</dc:date>
    <item>
      <title>Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687472#M208701</link>
      <description>&lt;P&gt;I am trying to filter outliers in my dataset. Specifically, I want to filter values outside the interval [0.5th percentile, 99.5th percentile]. I use the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC UNIVARIATE DATA = BDD;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; VAR AMOUNT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; OUTPUT OUT = TEMP&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; PCTLPRE = P_ PCTLPTS = 0.5, 99.5;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; SET TEMP;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; CALL SYMPUT('LB', P_0_5);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL SYMPUT('UB', P_99_5);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;However, when I try to then filter values, I get an error since the macro variables are stored as string, not numeric values. How could I use them as numeric in later steps?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687472#M208701</guid>
      <dc:creator>93alejandrosanc</dc:creator>
      <dc:date>2020-09-29T11:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687478#M208704</link>
      <description>&lt;P&gt;Please post the complete log of the step in which you use the macro variables and get the ERROR.&lt;/P&gt;
&lt;P&gt;Use this button to open a window into which you copy/paste the log text:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/8D8B612AA6AB1DC7E9A0812281D56E02/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687478#M208704</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T11:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687483#M208707</link>
      <description>&lt;P&gt;Your idea is basically sound, as can be proven with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc univariate data=sashelp.baseball;
var natbat;
output
  out=temp
  pctlpre=P_ 
  pctlpts = 0.5, 99.5
;
run;

data _null_;
set temp;
call symput('LB',P_0_5);
call symput('UB',P_99_5);
run;

data want;
set sashelp.baseball;
where natbat gt &amp;amp;lb. and natbat lt &amp;amp;ub.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which works as intended:&lt;/P&gt;
&lt;PRE&gt; 73         proc univariate data=sashelp.baseball;
 74         var natbat;
 75         output
 76           out=temp
 77           pctlpre=P_
 78           pctlpts = 0.5, 99.5
 79         ;
 80         run;
 
 NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
 NOTE:  Verwendet wurde: PROZEDUR UNIVARIATE - (Gesamtverarbeitungszeit):
       real time           0.10 seconds
       cpu time            0.10 seconds
       
 
 81         
 82         data _null_;
 83         set temp;
 84         call symput('LB',P_0_5);
 85         call symput('UB',P_99_5);
 86         run;
 
 NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       84:18   85:18   
 NOTE: There were 1 observations read from the data set WORK.TEMP.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 87         
 88         data want;
 89         set sashelp.baseball;
 90         where natbat gt &amp;amp;lb. and natbat lt &amp;amp;ub.;
 91         run;
 
 NOTE: There were 318 observations read from the data set SASHELP.BASEBALL.
       WHERE (natbat&amp;gt;127 and natbat&amp;lt;680);
 NOTE: The data set WORK.WANT has 318 observations and 24 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687483#M208707</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T12:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687485#M208708</link>
      <description>&lt;P&gt;Thanks for the reply! Actually, I just didn't realize SAS would interpret the macrovariables as numeric when using them in logical conditions. I'm new around here, if I need to delete the post just let me know!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687485#M208708</guid>
      <dc:creator>93alejandrosanc</dc:creator>
      <dc:date>2020-09-29T12:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687486#M208709</link>
      <description>&lt;P&gt;While symput will work, symputx is the better choice.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687486#M208709</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2020-09-29T12:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687488#M208710</link>
      <description>&lt;P&gt;Could you elaborate?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687488#M208710</guid>
      <dc:creator>93alejandrosanc</dc:creator>
      <dc:date>2020-09-29T12:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687489#M208711</link>
      <description>google symputx</description>
      <pubDate>Tue, 29 Sep 2020 12:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687489#M208711</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2020-09-29T12:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687490#M208712</link>
      <description>&lt;P&gt;You are correct in saying that macro variables are text, because the macro processor is a text engine. But that text is used as &lt;EM&gt;program text&lt;/EM&gt;, just as if you yourself typed it. If macro variables can be used in a certain place depends on the contents of the macro variables and the context.&lt;/P&gt;
&lt;P&gt;In your case, the macro variables contain text with a numeric value, and can be used in a place where numbers are required&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687490#M208712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T12:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687492#M208713</link>
      <description>&lt;P&gt;CALL SYMPUTX will do the conversion from numeric to character on its own, thereby avoiding the conversion NOTE in the log, and it allows you to control (through a third optional parameter) into which symbol table (local or global) a macro variable is stored.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687492#M208713</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T12:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Store numeric macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687497#M208716</link>
      <description>&lt;P&gt;In some cases the textual representation of a numeric value (i.e. default is a display format BEST12.) used by SYMPUTX that gets assigned to a macro variable is not EXACTLY the numeric value you want to use later on when the macro variable is resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remedies&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use format HEX16. to place an exact textual representation of the numeric value in a macro variable&lt;/LI&gt;
&lt;LI&gt;Use a merge or set to introduce the variable(s) to later DATA Step processing&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Example (macro)&lt;/P&gt;
&lt;PRE&gt;data have;
  z = 12345.99999999;
  call symputx ('z_mvar_rep1', z);  * rep means representation;
  call symput  ('z_mvar_rep2', put(z, hex16.));
run;

%put NOTE: &amp;amp;=z_mvar_rep1;
%put NOTE: &amp;amp;=z_mvar_rep2;

data later;
  set have;
  diff1 = z - &amp;amp;z_mvar_rep1;
  diff2 = z - input("&amp;amp;z_mvar_rep2", hex16.);
run;&lt;/PRE&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt;NOTE: Z_MVAR_REP1=12346
NOTE: Z_MVAR_REP2=40C81CFFFFFFEA86
&lt;/PRE&gt;
&lt;P&gt;Example (set)&lt;/P&gt;
&lt;PRE&gt;data later;
  set have;
  if _n_ = 1 then set have (rename=z=z_earlier);

  format z_earlier best20.;

  diff = z - z_earlier;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Store-numeric-macro-variable/m-p/687497#M208716</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-29T12:50:24Z</dc:date>
    </item>
  </channel>
</rss>

