<?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: searching through a directory in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61145#M17347</link>
    <description>I'm using a batch file for my SFTP.  I plan on having this output go to a file that the batch will reference when it runs.</description>
    <pubDate>Thu, 05 Aug 2010 18:59:28 GMT</pubDate>
    <dc:creator>nickb</dc:creator>
    <dc:date>2010-08-05T18:59:28Z</dc:date>
    <item>
      <title>searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61133#M17335</link>
      <description>I recently posted a question on how to strip leading zeros so that I could build up a FTP put statement.  It worked great but the first put statement referenced a file that doesn't exist.  I was wondering if there is a way to grab a directory and put it into a data set?  Once this is accomplished I can then join the valid files in the directory.&lt;BR /&gt;
&lt;BR /&gt;
Nick</description>
      <pubDate>Thu, 05 Aug 2010 17:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61133#M17335</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T17:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61134#M17336</link>
      <description>Take a look at the FEXIST function.  It can be used in the DATA step or with %SYSFUNC.  There are other solutions as well, but check this one out first.</description>
      <pubDate>Thu, 05 Aug 2010 17:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61134#M17336</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-08-05T17:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61135#M17337</link>
      <description>Couldn't you just use the FILEEXIST function to verify the file's existence?&lt;BR /&gt;
&lt;BR /&gt;
Robert</description>
      <pubDate>Thu, 05 Aug 2010 17:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61135#M17337</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-05T17:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61136#M17338</link>
      <description>I'm not familiar with that?  Will it give you the capability to continue on if the file doesn't exist?</description>
      <pubDate>Thu, 05 Aug 2010 17:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61136#M17338</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T17:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61137#M17339</link>
      <description>The two functions have different purposes - yes, you can code a SAS program to provide condition path-execution depending on the results of the function call -- most often done with SAS macro language but conceivably possible with DATA step code that generates subsequent-executed SAS statements (other PROCs or DATA steps).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 05 Aug 2010 17:39:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61137#M17339</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-05T17:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61138#M17340</link>
      <description>Sure, just include it in the flow of your datastep. Somewhat like&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
...&lt;BR /&gt;
if fileexist(your_file)=1 then put 'put ....' ;&lt;BR /&gt;
....&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Referring to your FTP problem, you will have to construct a variable containing the complete filename. In my example above that would be variable "your_file".&lt;BR /&gt;
&lt;BR /&gt;
Robert</description>
      <pubDate>Thu, 05 Aug 2010 17:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61138#M17340</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-05T17:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61139#M17341</link>
      <description>Both the FEXIST and the FILEEXIST functions allow you to verify that a file (or even a directory) exists on your system.  The function returns a value which you can test.</description>
      <pubDate>Thu, 05 Aug 2010 17:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61139#M17341</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-08-05T17:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61140#M17342</link>
      <description>I have one hard file value and it isn't working properly.  Also, there are 44,000 'put' statements that I need to verify on the directory.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
set work.display_data end=lastobs ;&lt;BR /&gt;
file max_pics;&lt;BR /&gt;
if _n_ = 1 then put 'cd incoming/images' ;&lt;BR /&gt;
idnum = input(person_id_nb,best.) ;&lt;BR /&gt;
if fileexist ("\\myfile\61.jpg")=1 &lt;BR /&gt;
then put 'put \\myfilepath' idnum +(-1) '.jpg' ;&lt;BR /&gt;
if lastobs then put 'quit' ;&lt;BR /&gt;
run ;</description>
      <pubDate>Thu, 05 Aug 2010 18:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61140#M17342</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T18:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61141#M17343</link>
      <description>No, you just have two statements that verify all 44,000 filenames, namely:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
my_file = '\\my_file\'!!trim(put(id,best.-l))!!'.jpg' ;&lt;BR /&gt;
if fileexist(my_file)=1 then put 'put ....' ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Robert</description>
      <pubDate>Thu, 05 Aug 2010 18:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61141#M17343</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-05T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61142#M17344</link>
      <description>still not working.&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
set work.display_data end=lastobs ;&lt;BR /&gt;
file max_pics;&lt;BR /&gt;
if _n_ = 1 then put 'cd incoming/images' ;&lt;BR /&gt;
idnum = input(person_id_nb,best.) ;&lt;BR /&gt;
my_file= '\\batgirl\webroot_root$\JRun4\servers\cfusion2\cfusion.ear\cfusion.war\data\images\'!!trim(put(idnum,best.-1))!!'.jpg' ;&lt;BR /&gt;
if fileexist (my_file)=1 then put my_file;&lt;BR /&gt;
if lastobs then put 'quit' ;&lt;BR /&gt;
run ;</description>
      <pubDate>Thu, 05 Aug 2010 18:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61142#M17344</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T18:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61143#M17345</link>
      <description>I see one typo in your my_file construction statement, where it should say "best.-L" not "best.-1". The -L suffix means "justified left" (although I think it is not really needed there).&lt;BR /&gt;
&lt;BR /&gt;
As an aside: things like this should always be tested with a minimal setup.&lt;BR /&gt;
&lt;BR /&gt;
Another point (and completely untested): you might need to quote my_file in the fileexist invocation, somewhat like&lt;BR /&gt;
&lt;BR /&gt;
if fileexist("'"!!my_file!!"'")   ....&lt;BR /&gt;
&lt;BR /&gt;
Time to go home now  ... kind regards&lt;BR /&gt;
Robert</description>
      <pubDate>Thu, 05 Aug 2010 18:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61143#M17345</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-08-05T18:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61144#M17346</link>
      <description>Also, you should test your code first by echoing it back to the SASLOG for your own desk-checking.....I don't see where you actually generate the FTP "put " command verb, only the file-name.  Hopefully you are reviewing any FTP log output, right?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 05 Aug 2010 18:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61144#M17346</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-05T18:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61145#M17347</link>
      <description>I'm using a batch file for my SFTP.  I plan on having this output go to a file that the batch will reference when it runs.</description>
      <pubDate>Thu, 05 Aug 2010 18:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61145#M17347</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T18:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61146#M17348</link>
      <description>Okay, so you have a "cd" command, a "quit" command, but no "put" command (verb)?  Only the file-name to be transfered is generated in the output file?  Is that what you are trying to say?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 05 Aug 2010 19:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61146#M17348</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-05T19:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61147#M17349</link>
      <description>For the most part.  My code is missing the 'put' statement and once I get this working, I will add it in.  The put statement will be based on the records that are in a temp dataset (roughly 40,000 ids) and of those ids, I only want the ones that exist in my lookup directory location.  Once the code is correct, I should have a put statement of ids that are in my temp data set and also exist in my lookup directory.  Basically, I'm trying to build up a 'PUT' statement for student pictures and I only want the ids in my temp dataset and those that are located in the pics directory.  I had the file built earlier but once the put statement encountered a file that didn't exist, it bombed.</description>
      <pubDate>Thu, 05 Aug 2010 19:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61147#M17349</guid>
      <dc:creator>nickb</dc:creator>
      <dc:date>2010-08-05T19:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: searching through a directory</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61148#M17350</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
The code below should give you an idea of how you could proceed.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename dirlist pipe 'dir c:\temp\*.jpg /b'; &lt;BR /&gt;
&lt;BR /&gt;
data dirlist;&lt;BR /&gt;
  infile dirlist delimiter='.';&lt;BR /&gt;
  input id:$32.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  length id $32;&lt;BR /&gt;
  do id='1','10','42','43','44';&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  /* declare hash table to look up ID from dirlist */&lt;BR /&gt;
  if _n_=1 then&lt;BR /&gt;
  do;&lt;BR /&gt;
    length id $32.;&lt;BR /&gt;
    declare hash h (dataset:'dirlist');&lt;BR /&gt;
    rc = h.defineKey('id');&lt;BR /&gt;
    rc = h.defineDone( );&lt;BR /&gt;
    call missing(id);&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
  set have;&lt;BR /&gt;
  if h.check()=0 then /* true if ID exists in lookup table */&lt;BR /&gt;
  do;&lt;BR /&gt;
    put 'ID ' id 'exists in the have table and as file under c:\temp';&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
For testing I've created two files under c:\temp : 2.jpg and 43.jpg&lt;BR /&gt;
&lt;BR /&gt;
Running the code above "putted" the following line to the log:&lt;BR /&gt;
"ID 43 exists in the have table and as file under c:\temp"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 05 Aug 2010 21:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-through-a-directory/m-p/61148#M17350</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-08-05T21:57:04Z</dc:date>
    </item>
  </channel>
</rss>

