<?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: Getting the value of a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673244#M202485</link>
    <description>Thank you very much!&lt;BR /&gt;Does it work if I test &amp;amp;l.^=.  (case of non-empty value)?</description>
    <pubDate>Wed, 29 Jul 2020 18:02:47 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2020-07-29T18:02:47Z</dc:date>
    <item>
      <title>Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673075#M202403</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm struggling to get a value from the macro variable with %eval function:&lt;/P&gt;
&lt;P&gt;%macro test2;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;k=1;&lt;BR /&gt;l=.;&lt;BR /&gt;call symputx('k',k);&lt;BR /&gt;call symputx('l',l);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%if %eval(&amp;amp;l.)=. %then %do;&lt;BR /&gt;%put "TEST MACRO";&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%test2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error is:&amp;nbsp;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &lt;BR /&gt;. &lt;BR /&gt;ERROR: The macro TEST2 will stop executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, I would like to execute the code conditionally (in the case of empty value of numeric macro variable).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Marie&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673075#M202403</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-29T10:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673078#M202406</link>
      <description>&lt;P&gt;%eval is for integer arithmetic or evaluating comparisons (which return integer values). And Macro value of . is not an integer.&lt;/P&gt;
&lt;P&gt;So you get that error.&lt;/P&gt;
&lt;P&gt;To see if the value of l is . use this code. WARNING: if you change the system option of missing from the default this will behave differently.&lt;/P&gt;
&lt;PRE&gt;%macro test2;

data test;
k=1;
l=.;
call symputx('k',k);
call symputx('l',l);
run;

%if &amp;amp;l.=. %then %do;  /* or %if  %eval(&amp;amp;l. = .) %then %do; */
%put "TEST MACRO";
%end;
%mend;

%test2;&lt;/PRE&gt;
&lt;P&gt;You might describe how you intend to use this in a bit more detail as missing values and macro variables can be a bit tricky.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673078#M202406</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-29T10:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673244#M202485</link>
      <description>Thank you very much!&lt;BR /&gt;Does it work if I test &amp;amp;l.^=.  (case of non-empty value)?</description>
      <pubDate>Wed, 29 Jul 2020 18:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673244#M202485</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-29T18:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673251#M202492</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much!&lt;BR /&gt;Does it work if I test &amp;amp;l.^=. (case of non-empty value)?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why not just try it and see?&amp;nbsp; Set the macro variable and then evaluate your test. 1 is TRUE and 0 is FALSE.&lt;/P&gt;
&lt;PRE&gt;854   %let x=.;
855   %put %eval(&amp;amp;x=.);
1
856   %put %eval(&amp;amp;x=);
0

857   %let x=;
858   %put %eval(&amp;amp;x=.);
0
859   %put %eval(&amp;amp;x=);
1

860   %let x=0;
861   %put %eval(&amp;amp;x=.);
0
862   %put %eval(&amp;amp;x=);
0

863   %let x=text;
864   %put %eval(&amp;amp;x=.);
0
865   %put %eval(&amp;amp;x=);
0
&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 18:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673251#M202492</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-29T18:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673329#M202542</link>
      <description>&lt;P&gt;I took a slightly different approach from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. I'm not sure that it's necessarily better, but perhaps it will be of value in some circumstances.&amp;nbsp; It's a little macro that will detect character or numeric missing values in a macro variable including special missing values.&amp;nbsp; The MISSING option should matter less, at least that's the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO	Test_For_Missing(Var, Debug=NO)	/	MINOPERATOR	MINDELIMITER=',';
	%LOCAL	lCmnt;

	%IF	%QUPCASE(&amp;amp;Debug)	=	YES										%THEN
		%DO;
			%LET	lCmnt	=	;
			%PUT	NOTE:  Debug is on in &amp;amp;Sysmacroname;
			%PUT	NOTE-  &amp;amp;Var is &amp;gt;&amp;amp;&amp;amp;&amp;amp;Var&amp;lt;;
		%END;
	%ELSE
		%DO;
			%LET	lCmnt	=	;
		%END;

	%IF	%BQUOTE(&amp;amp;&amp;amp;&amp;amp;Var)		=	%BQUOTE()								%THEN
		%DO;
			%PUT	NOTE:  &amp;amp;Var is missing.  Value is &amp;gt;&amp;amp;&amp;amp;&amp;amp;Var&amp;lt;;
		%END;
	%ELSE
	%IF	(%QUPCASE(&amp;amp;&amp;amp;&amp;amp;Var)	IN	(._,.,%STR(),%STR( ),.A,.B,.C,.D,.E,
								.F,.G,.H,.I,.J,.K,.L,.M,.N,.O,.P,
								.Q,.R,.S,.T,.U,.V,.W,.X,.Y,.Z))			%THEN
		%DO;
			%PUT	NOTE:  &amp;amp;Var is missing.  Value is &amp;gt;&amp;amp;&amp;amp;&amp;amp;Var&amp;lt;;
		%END;
	%ELSE
		%DO;
			%PUT	NOTE:  &amp;amp;Var is NOT missing.  Value is &amp;gt;&amp;amp;&amp;amp;&amp;amp;Var&amp;lt;;
		%END;
%MEND	Test_For_Missing;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here's some test code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET	Char_Missing	=	;
%LET	Num_Missing		=	.;
%LET	Spcl_Missing	=	.E;
%LET	Char_Var		=	Ham Sandwich;
%LET	Num_Var			=	07292020;

%LET	Save_Options	=	%SYSFUNC(GETOPTION(SOURCE)) %SYSFUNC(GETOPTION(SOURCE2)) PS=%SYSFUNC(GETOPTION(PS)) ;
OPTIONS	NOSOURCE	NOSOURCE2	PS=MAX;
%Test_For_Missing(Char_Missing, Debug=NO);
%Test_For_Missing(Num_Missing, Debug=NO);
%Test_For_Missing(Spcl_Missing, Debug=NO);
%Test_For_Missing(Char_Var, Debug=NO);
%Test_For_Missing(Num_Var, Debug=NO);
OPTIONS	&amp;amp;Save_Options;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which yields the following:&lt;/P&gt;
&lt;PRE&gt;NOTE:  Char_Missing is missing.  Value is &amp;gt;&amp;lt;
NOTE:  Num_Missing is missing.  Value is &amp;gt;.&amp;lt;
NOTE:  Spcl_Missing is missing.  Value is &amp;gt;.E&amp;lt;
NOTE:  Char_Var is NOT missing.  Value is &amp;gt;Ham Sandwich&amp;lt;
NOTE:  Num_Var is NOT missing.  Value is &amp;gt;07292020&amp;lt;&lt;/PRE&gt;
&lt;P&gt;I hope that is of some use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 22:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673329#M202542</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-07-29T22:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the value of a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673634#M202697</link>
      <description>Thank you very much!&lt;BR /&gt;I understood the problem:) &lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Marie</description>
      <pubDate>Fri, 31 Jul 2020 07:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-value-of-a-macro-variable/m-p/673634#M202697</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2020-07-31T07:58:48Z</dc:date>
    </item>
  </channel>
</rss>

