<?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 data _null_ conditionally in CAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-null-conditionally-in-CAS/m-p/833613#M329554</link>
    <description>&lt;P&gt;I want to include a ETL code if the file sashdat does not exist.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What works is the data _null_ on its own.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME REFFILE FILESRVC FOLDERPATH='/Projects/Residual_Value 3.0/'  FILENAME='_etl_fsvbala.sas';
data _null_;
%include reffile;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I don't know how to check for the existence of a certain file in sashdat format.&lt;/P&gt;
&lt;P&gt;The global logic what I want to achieve goes like this:&lt;/P&gt;
&lt;P&gt;If the file sashdat exists and the table with the same name is not loaded into memory, then load and promote the table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When neither file sashdat nor table exist, then include the ETL code shown above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I need to check for the file existence in the caslib and use this true/false variable to decide on running the %include statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to check for the existence of a table. I would like to adapt this code to file existence, but I suppose that I cannot use the data _null_ as a sourcecode block in proc cas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME REFFILE FILESRVC FOLDERPATH='/Projects/Residual_Value 3.0/'  FILENAME='_etl_fsvbala.sas';

%let casy=FSVBALA_&amp;amp;fc._OUTLIER;
%let liby=risknoba;

/* works */
cas mysession sessopts=(caslib="&amp;amp;liby");
proc cas;        
    table.tableExists result=e status=rc / 
        caslib = "&amp;amp;liby"
        name   = "&amp;amp;casy"
    ;
    /* If the data exists, set dataExists = 1 and grab the current report data */
    if(e.exists = 0) then do;
     table.loadtable / path="&amp;amp;casy..sashdat" casOut="&amp;amp;casy" caslib="&amp;amp;liby"; 
     table.promote /name="&amp;amp;casy" ;
print "hello";
  end;
run;

/* does not work properly, it executes the code but with error messages */
proc cas;        
    table.tableExists result=e status=rc / /* fileExists???
        caslib = "&amp;amp;liby"
        name   = "&amp;amp;casy";
    if(e.exists ^= 0) then do;

source myDataStep;
data _null_;
%include reffile;
run;
endsource;
   dataStep.runCode result=r status=rc / 
     code=myDataStep;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Sep 2022 14:47:01 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2022-09-15T14:47:01Z</dc:date>
    <item>
      <title>data _null_ conditionally in CAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-conditionally-in-CAS/m-p/833613#M329554</link>
      <description>&lt;P&gt;I want to include a ETL code if the file sashdat does not exist.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What works is the data _null_ on its own.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME REFFILE FILESRVC FOLDERPATH='/Projects/Residual_Value 3.0/'  FILENAME='_etl_fsvbala.sas';
data _null_;
%include reffile;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I don't know how to check for the existence of a certain file in sashdat format.&lt;/P&gt;
&lt;P&gt;The global logic what I want to achieve goes like this:&lt;/P&gt;
&lt;P&gt;If the file sashdat exists and the table with the same name is not loaded into memory, then load and promote the table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When neither file sashdat nor table exist, then include the ETL code shown above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I need to check for the file existence in the caslib and use this true/false variable to decide on running the %include statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to check for the existence of a table. I would like to adapt this code to file existence, but I suppose that I cannot use the data _null_ as a sourcecode block in proc cas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME REFFILE FILESRVC FOLDERPATH='/Projects/Residual_Value 3.0/'  FILENAME='_etl_fsvbala.sas';

%let casy=FSVBALA_&amp;amp;fc._OUTLIER;
%let liby=risknoba;

/* works */
cas mysession sessopts=(caslib="&amp;amp;liby");
proc cas;        
    table.tableExists result=e status=rc / 
        caslib = "&amp;amp;liby"
        name   = "&amp;amp;casy"
    ;
    /* If the data exists, set dataExists = 1 and grab the current report data */
    if(e.exists = 0) then do;
     table.loadtable / path="&amp;amp;casy..sashdat" casOut="&amp;amp;casy" caslib="&amp;amp;liby"; 
     table.promote /name="&amp;amp;casy" ;
print "hello";
  end;
run;

/* does not work properly, it executes the code but with error messages */
proc cas;        
    table.tableExists result=e status=rc / /* fileExists???
        caslib = "&amp;amp;liby"
        name   = "&amp;amp;casy";
    if(e.exists ^= 0) then do;

source myDataStep;
data _null_;
%include reffile;
run;
endsource;
   dataStep.runCode result=r status=rc / 
     code=myDataStep;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-conditionally-in-CAS/m-p/833613#M329554</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-09-15T14:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: data _null_ conditionally in CAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-null-conditionally-in-CAS/m-p/833626#M329561</link>
      <description>&lt;P&gt;I've tried to circumvent by using a call symputx within proc cas.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That works half-way because my coditional %include fires whatever value the macro variable file_true has.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let casy=FSVBALA_&amp;amp;fc._OUTLIER;
%let liby=risknoba;

cas mysession sessopts=(caslib="&amp;amp;liby");
proc cas;        
    table.tableExists result=e status=rc / 
        caslib = "&amp;amp;liby"
        name   = "&amp;amp;casy"
    ;
      call symputx("file_true", e.exists);
    /* If the data exists, set dataExists = 1 and grab the current report data */
    if(e.exists = 0) then do;
     table.loadtable / path="&amp;amp;casy..sashdat" casOut="&amp;amp;casy" caslib="&amp;amp;liby"; 
     table.promote /name="&amp;amp;casy";
  end;
run;

%put &amp;amp;file_true;

options mlogic symbolgen;

FILENAME REFFILE FILESRVC FOLDERPATH='/Projects/Residual_Value 3.0/'  FILENAME='_etl_fsvbala.sas';
data _null_;
if &amp;amp;file_true.=0 then do;
%include reffile;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-null-conditionally-in-CAS/m-p/833626#M329561</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2022-09-15T15:03:48Z</dc:date>
    </item>
  </channel>
</rss>

