<?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: A macro to check whether a variable is blank or not in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523017#M142057</link>
    <description>&lt;P&gt;up case===&amp;gt;upcase&lt;/P&gt;</description>
    <pubDate>Fri, 21 Dec 2018 07:31:20 GMT</pubDate>
    <dc:creator>learsaas</dc:creator>
    <dc:date>2018-12-21T07:31:20Z</dc:date>
    <item>
      <title>A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/522999#M142051</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you please help me knowing how to write a macro which reads a data set and corresponding variable and checking whether variable is blank or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example;&lt;/P&gt;&lt;P&gt;&amp;nbsp;%macro varcheck (dataset=,varaiable=)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 05:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/522999#M142051</guid>
      <dc:creator>niteshbharadwaj</dc:creator>
      <dc:date>2018-12-21T05:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523007#M142052</link>
      <description>&lt;P&gt;Please post example data and what you expect as result. Starting without any macro-code is highly recommended, as the task does not seems to require any macro-code, but this, of course, depends on what you want as result.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 06:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523007#M142052</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-12-21T06:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523008#M142053</link>
      <description>&lt;P&gt;This is my macro looks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro varexist(ds=,var=);&lt;BR /&gt;%local dsid rc ;&lt;BR /&gt;%let dsid = %sysfunc(open(&amp;amp;ds));&lt;BR /&gt;%if (&amp;amp;dsid) %then %do;&lt;BR /&gt;%if %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var)) %then 1;&lt;BR /&gt;%else 0 ;&lt;BR /&gt;%let rc = %sysfunc(close(&amp;amp;dsid));&lt;BR /&gt;%end;&lt;BR /&gt;%else 0;&lt;BR /&gt;%mend varexist;&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;&lt;P&gt;but here i want to check whether varaiable has null values or not instead of existing&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 06:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523008#M142053</guid>
      <dc:creator>niteshbharadwaj</dc:creator>
      <dc:date>2018-12-21T06:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523009#M142054</link>
      <description>&lt;P&gt;Still not clear what you want as result. Checking if a variable exists is NOT the same as checking whether a variable has missing-values. So, again, what do you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This example writes the number of missing values found to the log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create data to demonstrate the checking-step */
data work.class;
   set sashelp.class;

   if Age = 11 then Age = .;
run;


data _null_;
   set work.class end=jobDone;

   length missCount 8;

   missCount + missing(Age);

   if jobDone then do;
      put 'NOTE: Variable AGE is missing in ' missCount 'observations.';
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 06:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523009#M142054</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-12-21T06:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523011#M142055</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varcheck(dataset=sashelp.class,varaiable=age);
	%local nCount nMin nMax;
	proc contents data=&amp;amp;dataset out=temp(keep=name type) noprint;
	run;
	proc sql noprint;
		select count(*) into :nCount
		from temp
		where upcase(name)="%upcase(&amp;amp;varaiable)";
	quit;
	%if %left(&amp;amp;nCount) eq 0 %then %put *************NOT EXIST!**************; 
	%else %do;
		options missing='';
		proc sql noprint;
			select min(&amp;amp;varaiable),max(&amp;amp;varaiable) into :nMin,:nMax 
			from &amp;amp;dataset 
			;
		quit;
		%if "%left(&amp;amp;nMin)" eq "" and "%left(&amp;amp;nMax)" eq "" %then %put *************IS MISSING!**************; 	
	%end;
%mend;
%varcheck(dataset=sashelp.class,varaiable=age);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Dec 2018 06:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523011#M142055</guid>
      <dc:creator>learsaas</dc:creator>
      <dc:date>2018-12-21T06:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523016#M142056</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem almost got solved but while implementing the macro these are the below errors am receiving&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;6 proc contents data=&amp;amp;ds out=&amp;amp;temp(keep=name type) noprint; run; proc sql noprint; select count(*) into :nCount from &amp;amp;temp. where up case(name)="%upcase(&amp;amp;var)"; quit;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;&lt;DIV class="sasError"&gt;22&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, CONNECTION, DICTIONARY.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Thanks &amp;amp; Regards&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Nitesh&lt;/DIV&gt;</description>
      <pubDate>Fri, 21 Dec 2018 07:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523016#M142056</guid>
      <dc:creator>niteshbharadwaj</dc:creator>
      <dc:date>2018-12-21T07:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523017#M142057</link>
      <description>&lt;P&gt;up case===&amp;gt;upcase&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 07:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523017#M142057</guid>
      <dc:creator>learsaas</dc:creator>
      <dc:date>2018-12-21T07:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523040#M142065</link>
      <description>&lt;P&gt;even after correcting still the error exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help&lt;/P&gt;</description>
      <pubDate>Fri, 21 Dec 2018 12:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523040#M142065</guid>
      <dc:creator>niteshbharadwaj</dc:creator>
      <dc:date>2018-12-21T12:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523047#M142068</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output nlevels=want;
proc freq data=have nlevels;
table _all_;
run;
ods select all;
proc sql noprint;
select TableVar into : missing_variables separated by ' '
from want
where NNonMissLevels=0;
quit;
%put Missing variables are: &amp;amp;missing_variables ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Dec 2018 13:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523047#M142068</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-12-21T13:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: A macro to check whether a variable is blank or not in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523074#M142074</link>
      <description>&lt;P&gt;Please explain what you are trying to test for.&amp;nbsp; Since a variable can have a different value on each observation in a dataset what do you mean by a blank variable?&amp;nbsp; Do you want to know if it ever is blank? Or if it always is blank?&lt;/P&gt;
&lt;P&gt;What do you mean by blank?&amp;nbsp; Are you only testing character variables?&amp;nbsp; What about numeric variables?&amp;nbsp; Do you want to test for missing values?&amp;nbsp; What about special missing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variables do not have too many levels then a quick way to test if there are any missing (and any non-missing) values is to use the NLEVELS option on PROC FREQ.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have nlevels ;
  tables varname / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Dec 2018 14:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-macro-to-check-whether-a-variable-is-blank-or-not-in-the/m-p/523074#M142074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-21T14:43:42Z</dc:date>
    </item>
  </channel>
</rss>

