<?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: How to use an observation as a macro to the file path for importing the latest refreshed file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813898#M321265</link>
    <description>It gave me the below error:&lt;BR /&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;161:18 162:15 168:18&lt;BR /&gt;NOTE: Variable fref is uninitialized.&lt;BR /&gt;NOTE: Argument 1 to function DNUM(0) at line 163 column 15 is invalid.&lt;BR /&gt;ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY&lt;BR /&gt;expression is missing, zero, or invalid.&lt;BR /&gt;did=0 fref=. i=1 currentfile= fname= _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;1 at 163:15&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.03 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;BR /&gt;</description>
    <pubDate>Tue, 17 May 2022 18:08:01 GMT</pubDate>
    <dc:creator>L10_guri</dc:creator>
    <dc:date>2022-05-17T18:08:01Z</dc:date>
    <item>
      <title>How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813855#M321253</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello to every one!&lt;BR /&gt;I have a report in SAS that reads few .txt files that are distinguished from the date of the last refresh i.e&lt;/P&gt;&lt;P&gt;20220516_filenameabc&lt;/P&gt;&lt;P&gt;20220509_filenameabc&lt;/P&gt;&lt;P&gt;20220502_filenameabc&lt;/P&gt;&lt;P&gt;With the scripts below I was able to extract the latest refresh:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data filenames;
length fref $8 fname $200;
did = filename(fref,'path\Automated Extracts');
did = dopen(fref);
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
did = dclose(did);
did = filename(fref);
keep fname;
run;


data latest;
set filenames;
length ldate $8 ;
ldate = substr(fname, 1,8);
if substr (ldate ,1,1) ~= 2 then delete ;
drop fname ;
run;


proc sort data = latest;
by descending ldate ; run;
proc sort nodupkey data = latest;
by descending ldate ; run;

data latestd ;
set latest (OBS=1 FirstOBS=1) ; run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_dataset.jpg" style="width: 294px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71555iBE79AE314D6EEA2F/image-dimensions/294x132?v=v2" width="294" height="132" role="button" title="SAS_dataset.jpg" alt="SAS_dataset.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The part that I want to automate is this:&lt;BR /&gt;%LET INDATAFILE7 = 'path\Automated Extracts\&lt;STRONG&gt;20220516&lt;/STRONG&gt;_filenameabc.txt';&lt;BR /&gt;Instead of manually updating here &lt;STRONG&gt;20220516&lt;/STRONG&gt; to use a macro that reads this from the dataset created with the above script so I don't need to go every time that I run the report to check the latest file and manually change that part!&lt;BR /&gt;&lt;BR /&gt;Any suggestion what I can do better here?&lt;BR /&gt;&lt;BR /&gt;Thanks for your time and support!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 16:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813855#M321253</guid>
      <dc:creator>L10_guri</dc:creator>
      <dc:date>2022-05-17T16:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813857#M321254</link>
      <description>&lt;P&gt;You don't need a macro to read all text files in a folder. You can simply use an *.txt in the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2018/10/09/read-multiple-text-files/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2018/10/09/read-multiple-text-files/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 16:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813857#M321254</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-17T16:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813859#M321256</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set work.latestd;
  call symputx('INDATAFILE7','path\Automated Extracts\'||ldate||'_filenameabc.txt');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 16:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813859#M321256</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-05-17T16:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813889#M321260</link>
      <description>The folder that has the files has more files that I'm looking to import in SAS. I need to get the most refreshed one.&lt;BR /&gt;Currently the folder has more than 350 files with different dates when the file was refreshed. The unique ones are only 5. That is the reason that I'm trying to get these one only!&lt;BR /&gt;Thanks for checking!</description>
      <pubDate>Tue, 17 May 2022 17:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813889#M321260</guid>
      <dc:creator>L10_guri</dc:creator>
      <dc:date>2022-05-17T17:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813892#M321262</link>
      <description>&lt;P&gt;If your files are named like &amp;lt;YYYYMMDD&amp;gt;_&amp;lt;something else&amp;gt;, this may work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  did = filename(fref,'path\Automated Extracts');
  did = dopen(fref);
  do i = 1 to dnum(did);&lt;BR /&gt;     currentfile=dread(did,i);
     if substr(currentfile,1,1)='2' and fname&amp;lt;currentfile then fname=currentfile;
    end;
  call symputx('INDATAFILE7','path\Automated Extracts\'||fname);
  did = dclose(did);
  did = filename(fref);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which should give you the filename beginning with "2" having the highest (latest) filename in your macro variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;INDATAFILE7.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 17:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813892#M321262</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-05-17T17:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813898#M321265</link>
      <description>It gave me the below error:&lt;BR /&gt;&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;BR /&gt;161:18 162:15 168:18&lt;BR /&gt;NOTE: Variable fref is uninitialized.&lt;BR /&gt;NOTE: Argument 1 to function DNUM(0) at line 163 column 15 is invalid.&lt;BR /&gt;ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY&lt;BR /&gt;expression is missing, zero, or invalid.&lt;BR /&gt;did=0 fref=. i=1 currentfile= fname= _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;1 at 163:15&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.03 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;BR /&gt;</description>
      <pubDate>Tue, 17 May 2022 18:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813898#M321265</guid>
      <dc:creator>L10_guri</dc:creator>
      <dc:date>2022-05-17T18:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813901#M321267</link>
      <description>&lt;P&gt;Just put the name of the most recent file into a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select fname into :fname trimmed
   from filenames 
   order by fname desc
   where fname like '202%'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the macro variable use it in your code that reads the file.&lt;/P&gt;
&lt;P&gt;Make sure to use double quotes around the string so that the macro variable value is resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile "path/Automated Extracts/&amp;amp;fname" .... ;
  ...
run;&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Tue, 17 May 2022 18:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/813901#M321267</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-17T18:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use an observation as a macro to the file path for importing the latest refreshed file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/814022#M321307</link>
      <description>&lt;P&gt;Please use the search function, your issue has been asked and answers multiple times, so you will find something useful.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 10:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-an-observation-as-a-macro-to-the-file-path-for/m-p/814022#M321307</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-05-18T10:18:55Z</dc:date>
    </item>
  </channel>
</rss>

