<?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: uninitialized in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953612#M372546</link>
    <description>&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/01/23/putlog-statement.html" target="_blank" rel="noopener"&gt;Use the PUTLOG statement to write errors, warning, and notes to the SAS log - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I produce a &lt;FONT color="#008000"&gt;WARNING&lt;/FONT&gt; for your case ... but you need an input dataset (set statement) in your data step to make it work !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x=10;
run;

/* The macro %VAREXIST checks to see if a specific variable exists on a specified data set. */
%macro varexist(dsn=class,varname=age); 
%local dsid vnum;
%let vnum=0;
%let dsid = %sysfunc(open(&amp;amp;dsn));
%if &amp;amp;dsid %then %do;
   %let vnum = %sysfunc(varnum(&amp;amp;dsid,&amp;amp;varname));
   %let dsid = %sysfunc(close(&amp;amp;dsid)); 
%end;
&amp;amp;vnum
%mend varexist; 

data want;
 set have;
%if %varexist(dsn=have,varname=x)^=0 %then %do; 
   putlog "NOTE: x-variable is IN input dataset"; 
%end;
%if %varexist(dsn=have,varname=x) %then %do; 
 y=x*5;
%end;
run;

data want;
 set have;
%if %varexist(dsn=have,varname=z)=0 %then %do; 
   putlog "WARNING: z-variable NOT IN input dataset"; 
%end;
%if %varexist(dsn=have,varname=z) %then %do; 
 y=z*5;
%end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ciao, Koen&lt;/P&gt;</description>
    <pubDate>Sun, 15 Dec 2024 11:50:56 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2024-12-15T11:50:56Z</dc:date>
    <item>
      <title>uninitialized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953610#M372544</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Is it possible to tell SAS to give error when "uninitialized".&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;I want to get error here and I even dont see warning&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
X=10;
run;

data want;
y=z*5;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Dec 2024 09:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953610#M372544</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-12-15T09:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: uninitialized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953611#M372545</link>
      <description>&lt;P&gt;What is the problem here? You can search the log for "uninitialized", just like you can search the log for "ERROR".&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 10:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953611#M372545</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-15T10:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: uninitialized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953612#M372546</link>
      <description>&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/01/23/putlog-statement.html" target="_blank" rel="noopener"&gt;Use the PUTLOG statement to write errors, warning, and notes to the SAS log - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I produce a &lt;FONT color="#008000"&gt;WARNING&lt;/FONT&gt; for your case ... but you need an input dataset (set statement) in your data step to make it work !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x=10;
run;

/* The macro %VAREXIST checks to see if a specific variable exists on a specified data set. */
%macro varexist(dsn=class,varname=age); 
%local dsid vnum;
%let vnum=0;
%let dsid = %sysfunc(open(&amp;amp;dsn));
%if &amp;amp;dsid %then %do;
   %let vnum = %sysfunc(varnum(&amp;amp;dsid,&amp;amp;varname));
   %let dsid = %sysfunc(close(&amp;amp;dsid)); 
%end;
&amp;amp;vnum
%mend varexist; 

data want;
 set have;
%if %varexist(dsn=have,varname=x)^=0 %then %do; 
   putlog "NOTE: x-variable is IN input dataset"; 
%end;
%if %varexist(dsn=have,varname=x) %then %do; 
 y=x*5;
%end;
run;

data want;
 set have;
%if %varexist(dsn=have,varname=z)=0 %then %do; 
   putlog "WARNING: z-variable NOT IN input dataset"; 
%end;
%if %varexist(dsn=have,varname=z) %then %do; 
 y=z*5;
%end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ciao, Koen&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 11:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953612#M372546</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-12-15T11:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: uninitialized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953613#M372547</link>
      <description>&lt;P&gt;You can use the VARINITCHK system option, and set it to ERROR (or WARN if you only want a warning):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    options varinitchk=error;
2
3    data want;
4    y=z*5;
5    Run;

ERROR: Variable z is uninitialized.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 0 observations and 2 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 12:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953613#M372547</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-12-15T12:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: uninitialized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953618#M372548</link>
      <description>I prefer that program make error and stop execute in such situation.  I might miss it by looking at log</description>
      <pubDate>Sun, 15 Dec 2024 22:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/uninitialized/m-p/953618#M372548</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-12-15T22:34:18Z</dc:date>
    </item>
  </channel>
</rss>

