<?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: Error while executing a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403129#M278896</link>
    <description>&lt;P&gt;Please post Code and Log using {i} or running-man icon. To debug errors the log is almost always required. Check Variable did, maybe dopen failed.&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2017 12:35:48 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2017-10-11T12:35:48Z</dc:date>
    <item>
      <title>Error while executing a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403118#M278895</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options msglevel=i;
libname in1 "/sascommon/sasusers/ksnm843";
%let subdir=/sascommon/gridnode01/config/Lev1/SASApp94/WorkspaceServer/RTRACE_LOGS;
data work.dirlist(keep=filename strUser ModDT CrDT strPID strSource);
/* must be explicitly set to blank to have the filename function generate a fileref */
fileref = '      ';
rc = filename(fileref,"&amp;amp;subdir");
/* open fileref and loop throughfilenames */
did=dopen(fileref);
do i = 1 to dnum(did);
/* extract filename */
fileName = dread(did,i);
/* find the position of PID in the filename */
pid_start = index(fileName,"PID")+3;
/* find the end position of PIF in filename */
pid_end = index(fileName,"DATE")-1;
/* extract PID */
strPID = substr(fileName,pid_start,pid_end - pid_start);
/* find the start of DATE in filename */
date_start = index(fileName,"DATE")+4;
/* find the end position of DATE in the filename */
date_end = index(fileName,":")-1;
/* set the start of the time field */
time_start = date_end +2;
/* find the end of the time field */
time_end = index(filename,".");
/* extract creation time */
tmpTime = Trim(substr(filename, time_start, time_end - time_start));
tmpHour = Substr(tmpTime,1, 2)*1;
tmpMin = Substr(tmpTime,3,2)*1;
tmpSec = Substr(tmpTime,5,2)*1;
/* extract creation date */
strDT = trim(substr(fileName,date_start,date_end - (date_start-1)));
tmpDT = input(put(strDT,8.),yymmdd8.);
CrDt = DHMS(put(tmpDT,8.),tmpHour,tmpMin,tmpSec);
fid = mopen(did,fileName);
infonum=foptnum(fid);
if fid then do;
/* extract userid */
strUser=finfo(fid, foptname(fid, 2));
/* extract file modified date */
ModDT=input(trim(finfo(fid, foptname(fid, 5))),datetime20.);
format ModDT CrDT datetime20.;
/* extract file location */
strSource = finfo(fid, foptname(fid, 1));
output;
end;
end;
rc = dclose(did);
rc = filename(fileref);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got the following error when I executed the above mentioned program&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;or invalid.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also attached the detailed log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Please help me resolve this error&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 15:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403118#M278895</guid>
      <dc:creator>Sangavi</dc:creator>
      <dc:date>2017-10-11T15:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error while executing a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403129#M278896</link>
      <description>&lt;P&gt;Please post Code and Log using {i} or running-man icon. To debug errors the log is almost always required. Check Variable did, maybe dopen failed.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 12:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403129#M278896</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-10-11T12:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error while executing a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403145#M278897</link>
      <description>&lt;P&gt;When code fails, use put statements to show the state of variables during execution. Doing this, I discovered that your dopen() call returns zero, which points to an invalid fileref. This happens because you did not use a valid name (an empty string is no name) for your fileref.&lt;/P&gt;
&lt;P&gt;Do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.dirlist (keep=filename strUser ModDT CrDT strPID strSource);
fileref = 'mydir';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the rest of the step will work somewhat. You'll get lots of messages because you treat numeric variables/values incorrectly (using substr() directly on a numeric variable usually returns bogus).&lt;/P&gt;
&lt;P&gt;Make sure to properly convert numbers to strings, or use the proper functions to retrieve hours/minutes/seconds from time values.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 13:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403145#M278897</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-11T13:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Error while executing a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403154#M278898</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;already indicates the main reason that you're code is failing is due to below statement:&lt;/P&gt;
&lt;PRE&gt;fileref = ' ';&lt;/PRE&gt;
&lt;P&gt;This creates your variable &lt;EM&gt;fileref &lt;/EM&gt;(give it another name)&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;with a length of 1 character which is too short to hold a fileref which can be up to 8 characters.&lt;/P&gt;
&lt;P&gt;Add the following and the syntax error will go away (unlike all the warnings caused by other&amp;nbsp;less than perfect code bits):&lt;/P&gt;
&lt;PRE&gt;length fileref $8;
call missing(fileref);
&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 13:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403154#M278898</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-11T13:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error while executing a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403225#M278899</link>
      <description>&lt;P&gt;Thank you so much !&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; This worked !!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 16:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-while-executing-a-data-step/m-p/403225#M278899</guid>
      <dc:creator>Sangavi</dc:creator>
      <dc:date>2017-10-11T16:01:01Z</dc:date>
    </item>
  </channel>
</rss>

