<?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: create character macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559058#M156078</link>
    <description>&lt;P&gt;There's no such thing in SAS as a numeric macro variable. They are all character. Even if they look to us humans as a number, SAS considers it to be character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, your description of the problem needs a lot more details before we can provide any meaningful advice&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 16:36:24 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-05-15T16:36:24Z</dc:date>
    <item>
      <title>create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559052#M156073</link>
      <description>&lt;P&gt;Hi guy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro variable using the following statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select max(par_dt) into :var from ookla.ookla_all_stats;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the point is the "var" variable is always of numeric type even through par_dt is character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I need to use the 'var' variable in a where statement of a proc imstat where no data type conversion can take place )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody have an idea of how to do that ?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559052#M156073</guid>
      <dc:creator>VanDalucas</dc:creator>
      <dc:date>2019-05-15T16:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559058#M156078</link>
      <description>&lt;P&gt;There's no such thing in SAS as a numeric macro variable. They are all character. Even if they look to us humans as a number, SAS considers it to be character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, your description of the problem needs a lot more details before we can provide any meaningful advice&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559058#M156078</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-15T16:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559061#M156080</link>
      <description>&lt;P&gt;Macro variables always contain text.&amp;nbsp; The text might look like numbers and if you use them in a place where SAS expects to see a number then when expanded they will be treated by SAS as a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your PAR_DT variable is a valid date (or datetime) value then your code will pull out the unformatted number.&amp;nbsp; &amp;nbsp;You can then use this number in your code to compare to the values of PAR_DT variable (or any other number).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note since you didn't tell PROC SQL how to format the max value it will use BEST8. , which can be too short for raw datetime values (number of seconds since 1960).&amp;nbsp; So instead of getting a value like&amp;nbsp;1873543197 you will get&amp;nbsp;1.8735E9.&amp;nbsp; Just tell SAS to use a longer format.&amp;nbsp; You probably don't have fractions of a second so just use the 32. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
%let var=.;
select max(par_dt) format=32.
  into :var trimmed 
from ookla.ookla_all_stats
;
quit;

data want;
  set ookla.ookla_all_stats;
  where par_dt = &amp;amp;var ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559061#M156080</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-15T16:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559062#M156081</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80586"&gt;@VanDalucas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi guy,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a macro variable using the following statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select max(par_dt) into :var from ookla.ookla_all_stats;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff"&gt;the point is the "var" variable is always of numeric type even through par_dt is character.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I need to use the 'var' variable in a where statement of a proc imstat where no data type conversion can take place )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anybody have an idea of how to do that ?&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Prove that "var" is numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you want to very closely examine any process involving Max or Min functions involving character values. Max of "9" "1000" ".45" is what?&lt;/P&gt;
&lt;P&gt;All macro variables are always text. Some just look like numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If var is a single value then likely you need to do one of two things: in the where clause you reverence the variable place the macro variable inside double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where&amp;nbsp; myvariable = "&amp;amp;var."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;OR place the quotes inside the macro value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
select quote(strip(max(par_dt))) into :var from ookla.ookla_all_stats;
run;&lt;/PRE&gt;
&lt;P&gt;and use as&lt;/P&gt;
&lt;P&gt;where myvariable =&amp;amp;var.;&lt;/P&gt;
&lt;P&gt;The strip is likely needed to prevent have trailing spaces inside the quotes which would make "Yes" not equal to "Yes&amp;nbsp;&amp;nbsp; ".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559062#M156081</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-15T16:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559065#M156083</link>
      <description>&lt;P&gt;Macro variables do not have types, they are always just text. There is no such thing as a numeric macro variable, it can only contain text that looks like a number (and can be used as such, under specific circumstances).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And maximums of character variables can be tricky, as already mentioned.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559065#M156083</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-15T16:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: create character macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559066#M156084</link>
      <description>&lt;P&gt;Guys thanks you all for your posts!&lt;/P&gt;&lt;P&gt;yes, it appears that all I needed to&amp;nbsp; do was to enclose the var in ".."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-character-macro-variable/m-p/559066#M156084</guid>
      <dc:creator>VanDalucas</dc:creator>
      <dc:date>2019-05-15T16:56:38Z</dc:date>
    </item>
  </channel>
</rss>

