<?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 Is it possible to read local files with URL filename? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857523#M338829</link>
    <description>&lt;P&gt;Hey SAS-C,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I writing a code which usually takes URLs but occasionally a local file my pop up.&lt;/P&gt;
&lt;P&gt;My question is: &lt;EM&gt;Is it possible to read local files with URL filename?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below produces errors:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in URL "file://localhost/C:/directory/test.txt" 
debug recfm=N lrecl=1;

data _null_;
  ex=fexist("in");
  exTEXT = sysmsg();
  put ex= / exTEXT = /;
run;

filename in;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The exTEXT returns: "&lt;EM&gt;ERROR: Physical file does not exist&lt;/EM&gt;" even tough the file exists (pasting the same to chrome opens it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally the last line produce:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;ERROR: At least one file associated with fileref IN is still in use.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ERROR: Error in the FILENAME statement.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 11:09:11 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2023-02-07T11:09:11Z</dc:date>
    <item>
      <title>Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857523#M338829</link>
      <description>&lt;P&gt;Hey SAS-C,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I writing a code which usually takes URLs but occasionally a local file my pop up.&lt;/P&gt;
&lt;P&gt;My question is: &lt;EM&gt;Is it possible to read local files with URL filename?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code below produces errors:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in URL "file://localhost/C:/directory/test.txt" 
debug recfm=N lrecl=1;

data _null_;
  ex=fexist("in");
  exTEXT = sysmsg();
  put ex= / exTEXT = /;
run;

filename in;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The exTEXT returns: "&lt;EM&gt;ERROR: Physical file does not exist&lt;/EM&gt;" even tough the file exists (pasting the same to chrome opens it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally the last line produce:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;ERROR: At least one file associated with fileref IN is still in use.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;ERROR: Error in the FILENAME statement.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 11:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857523#M338829</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-02-07T11:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857537#M338834</link>
      <description>&lt;P&gt;If SAS is running on a server, that server won't be able to access your local computer.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857537#M338834</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-02-07T13:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857539#M338835</link>
      <description>&lt;P&gt;If SAS is running on the server then the path would be:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;filename in URL "file://localhost/home/&amp;amp;sysuserid./directory/test.txt" 
debug recfm=N lrecl=1;&lt;/LI-CODE&gt;
&lt;P&gt;It doesn't matter if it is a laptop or a server, thing is about "to access a file on the machine by URL"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857539#M338835</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-02-07T13:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857625#M338876</link>
      <description>&lt;P&gt;The documentation of the FILENAME URL statement lists only http and https access methods.&lt;/P&gt;
&lt;P&gt;You will need to work around this with macro code that executes the proper statement for the filename which is delivered to your code.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 18:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857625#M338876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-07T18:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857664#M338886</link>
      <description>&lt;P&gt;True, it only mentions "http*", at least that part about the filename statement. I was hoping that maybe I missed some other place in the doc... but looks like there is no such place &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 21:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857664#M338886</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-02-07T21:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to read local files with URL filename?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857669#M338887</link>
      <description>&lt;P data-unlink="true"&gt;If the string literally starts with 'FILE://LOCALHOST/'&amp;nbsp; then just adjust the string.&lt;/P&gt;
&lt;P data-unlink="true"&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input path $200.;
cards;
https://raw.githubusercontent.com/sasutils/macros/master/squote.sas
file://localhost/c:/downloads/squote.sas
;

data connections;
  length fileref $8 engine $8 ;
  set have;
  fileref=cats('file',_n_);
  if lowcase(path) in: ('http:','https:') then engine='url';
  else if lowcase(path) =: 'file://localhost/' then do;
    engine='disk';
    path=substrn(path,18);
  end;
  else engine='disk';
  call execute(catx(' ','filename',fileref,engine,quote(trim(path)),';'));
run;

data _null_;
  infile file1 ;
  input;
  put _infile_;
run;

data _null_;
  infile file2;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1970  data connections;
1971    length fileref $8 engine $8 ;
1972    set have;
1973    fileref=cats('file',_n_);
1974    if lowcase(path) in: ('http:','https:') then engine='url';
1975    else if lowcase(path) =: 'file://localhost/' then do;
1976      engine='disk';
1977      path=substrn(path,18);
1978    end;
1979    else engine='disk';
1980    call execute(catx('
1980! ','filename',fileref,engine,quote(trim(path)),';'));
1981  run;

NOTE: The data set WORK.CONNECTIONS has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


NOTE: CALL EXECUTE generated line.
1    + filename file1 url
"https://raw.githubusercontent.com/sasutils/macros/master/squote.sas" ;
2    + filename file2 disk "c:/downloads/squote.sas" ;
1982
1983  data _null_;
1984    infile file1 ;
1985    input;
1986    put _infile_;
1987  run;

NOTE: The infile FILE1 is:
      (system-specific pathname),
      (system-specific file attributes)

%macro squote(value);
%if %sysevalf(&amp;amp;sysver &amp;lt; 9.3) %then
%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
;
%else %sysfunc(quote(%superq(value),%str(%'))) ;
%mend squote;
NOTE: 6 records were read from the infile (system-specific pathname).
      The minimum record length was 1.
      The maximum record length was 72.
NOTE: DATA statement used (Total process time):
      real time           5.00 seconds
      cpu time            0.03 seconds


1988
1989  data _null_;
1990    infile file2;
1991    input;
1992    put _infile_;
1993  run;

NOTE: The infile FILE2 is:
      (system-specific pathname),
      (system-specific file attributes)

%macro squote(value);
%if %sysevalf(&amp;amp;sysver &amp;lt; 9.3) %then
%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
;
%else %sysfunc(quote(%superq(value),%str(%'))) ;
%mend squote;
NOTE: 6 records were read from the infile (system-specific pathname).
      The minimum record length was 1.
      The maximum record length was 72.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 21:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-read-local-files-with-URL-filename/m-p/857669#M338887</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-07T21:17:51Z</dc:date>
    </item>
  </channel>
</rss>

