<?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 How to check if a macro variable is blank in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160327#M31213</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried to do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test; test1;&lt;/P&gt;&lt;P&gt;Var1 = Column_&amp;amp;col1.; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if the "&amp;amp;col" is empty then I would get a error warning in the log file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to check whether my macro variable "&amp;amp;col" is empty?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried : &lt;/P&gt;&lt;P&gt;%if %length(&amp;amp;col.) = 0 %then %let col=blank;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but it turned out the %length(&amp;amp;col) = 4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Mar 2014 19:18:22 GMT</pubDate>
    <dc:creator>Ken_oy</dc:creator>
    <dc:date>2014-03-28T19:18:22Z</dc:date>
    <item>
      <title>How to check if a macro variable is blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160327#M31213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried to do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test; test1;&lt;/P&gt;&lt;P&gt;Var1 = Column_&amp;amp;col1.; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if the "&amp;amp;col" is empty then I would get a error warning in the log file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to check whether my macro variable "&amp;amp;col" is empty?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried : &lt;/P&gt;&lt;P&gt;%if %length(&amp;amp;col.) = 0 %then %let col=blank;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but it turned out the %length(&amp;amp;col) = 4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions? Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 19:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160327#M31213</guid>
      <dc:creator>Ken_oy</dc:creator>
      <dc:date>2014-03-28T19:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a macro variable is blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160328#M31214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;/* macro to test macro parameters&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;/* returns 1 if the tested parameter is blank */&lt;BR /&gt;/* 0 otherwise, blank means all charaters are,*/&lt;BR /&gt;/* or are macro variables that resolve to a,&amp;nbsp; */&lt;BR /&gt;/* blank&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;/* param can be upto 65,531 characters long&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;/* if numeric and several 1000 digits long may*/&lt;BR /&gt;/* hang the session. (Windows 32 bit OS)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;/* NOT a test for a NULL (zero length string) */&lt;BR /&gt;/* though may work for some of those as well&amp;nbsp; */&lt;/P&gt;&lt;P&gt;%macro isBlank(param);&lt;BR /&gt;%sysevalf(%superq(param)=,boolean)&lt;BR /&gt;%mend isBlank;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if %isblank(&amp;amp;var) = 1 %then;&lt;/P&gt;&lt;P&gt;%else ;&lt;/P&gt;&lt;P&gt;or similar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 20:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160328#M31214</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-03-28T20:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a macro variable is blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160329#M31215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, BallardW!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But just curious that SAS does not have its own function for this. :smileygrin:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 20:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160329#M31215</guid>
      <dc:creator>Ken_oy</dc:creator>
      <dc:date>2014-03-28T20:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a macro variable is blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160330#M31216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you are talking about as if COL1 is totally null (length of zero) or only contains blanks it should not cause any problem with that code.&amp;nbsp; It might not work as expected since the variable name generated might not match any actual variable, but it will not generate an error.&amp;nbsp; But then again you would have the same problem with any non empty value.&amp;nbsp; What could cause an error would be a value that includes a space.&amp;nbsp; You could test for that using a number of tests.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if %sysfunc(countw(&amp;amp;col1,%str( )) &amp;gt; 1 %then %put Value of COL1 contains more than one word ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read this paper &lt;A href="http://changchung.com/download/022-2009.pdf" title="http://changchung.com/download/022-2009.pdf"&gt;http://changchung.com/download/022-2009.pdf&lt;/A&gt;&amp;nbsp; for a test that checks if a macro variable is either empty (length of zero) OR contains spaces.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Mar 2014 21:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-macro-variable-is-blank/m-p/160330#M31216</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-28T21:08:01Z</dc:date>
    </item>
  </channel>
</rss>

