<?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: Loop over all .cpt files in a directory and export in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747401#M234574</link>
    <description>&lt;P&gt;Most of the files are "zipcode_xxxx.cpt" with some of the files including a version number i.e. "zipcode_xxxx_vx.cpt". The first two x's are jan, apr, jul, oct and the last two xx's are dates 11,12,13,14, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a similar issue when the downloaded files were in .zip format. I used R to unzip the files into a directory of my choosing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#1.1: Unzip files

    #A. Grab directory of zip files
    file.name.zip &amp;lt;- dir(raw_data_path, pattern=".zip")
    
    #B. Loop through directory
    for (zzz in file.name.zip) {
      print(zzz)
      unzip(paste(raw_data_path, zzz, sep="\\"),exdir=new_data_path)
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does SAS have a function, similar to&amp;nbsp;&lt;SPAN style="background-color: #f5f5f5; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px;"&gt;dir(raw_data_path, pattern=".zip")&lt;/SPAN&gt;, that creates a list of values found in a directory given a file pattern? For instance I would want to replace the previous function ".zip" with ".cpt".&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jun 2021 16:41:13 GMT</pubDate>
    <dc:creator>otteheng</dc:creator>
    <dc:date>2021-06-11T16:41:13Z</dc:date>
    <item>
      <title>Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747384#M234564</link>
      <description>&lt;P&gt;I have directory with a couple hundred .cpt files that I would like to export as sas7bdat files into a new directory. I am using SAS Viya&amp;nbsp;&lt;SPAN&gt;V.03.05 (SAS Studio Enterprise).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I have this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cas cta_session;
	caslib _all_ assign;

filename cptfile filesrvc folderpath='/Users/REMOVED/cptfiles' name='zcta_counties.cpt';

libname zipfiles '/home/REMOVED';
proc cimport infile=cptfile library=zipfiles; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could replace the&amp;nbsp;&lt;CODE class=" language-sas"&gt;name='FILE-NAME.cpt&lt;/CODE&gt;&amp;nbsp;one by one but given how many files I have the process is a bit time intensive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to loop through every .cpt in my folderpath?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&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>Fri, 11 Jun 2021 15:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747384#M234564</guid>
      <dc:creator>otteheng</dc:creator>
      <dc:date>2021-06-11T15:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747387#M234565</link>
      <description>&lt;P&gt;Do you have a naming convention or a list of files or do you need to create that list of files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're likely going into macro territory so here are some links that will be helpful&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UCLA introductory tutorial on macro variables and macros&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Tutorial on converting a working program to a macro&lt;/STRONG&gt;&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Examples of common macro usage (from documentation)&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 15:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747387#M234565</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-11T15:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747394#M234568</link>
      <description>&lt;P&gt;Have you looked at the FILEVAR option?&amp;nbsp; If you can create a list of the files you want (maybe an ls -l *.cpt with the output directed to a text file), you should be able to read that list into SAS and then use the FILEVAR option to read the files themselves.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also:&amp;nbsp;&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi27/p082-27.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi27/p082-27.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S.&amp;nbsp; I'm not currently working on UNIX.&amp;nbsp; I put ls -l because that's what I remember off the top of my head, but I'm sure there's a better option than -l to produce exactly what you want without superfluous information.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 16:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747394#M234568</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-11T16:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747401#M234574</link>
      <description>&lt;P&gt;Most of the files are "zipcode_xxxx.cpt" with some of the files including a version number i.e. "zipcode_xxxx_vx.cpt". The first two x's are jan, apr, jul, oct and the last two xx's are dates 11,12,13,14, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a similar issue when the downloaded files were in .zip format. I used R to unzip the files into a directory of my choosing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#1.1: Unzip files

    #A. Grab directory of zip files
    file.name.zip &amp;lt;- dir(raw_data_path, pattern=".zip")
    
    #B. Loop through directory
    for (zzz in file.name.zip) {
      print(zzz)
      unzip(paste(raw_data_path, zzz, sep="\\"),exdir=new_data_path)
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does SAS have a function, similar to&amp;nbsp;&lt;SPAN style="background-color: #f5f5f5; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px;"&gt;dir(raw_data_path, pattern=".zip")&lt;/SPAN&gt;, that creates a list of values found in a directory given a file pattern? For instance I would want to replace the previous function ".zip" with ".cpt".&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 16:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747401#M234574</guid>
      <dc:creator>otteheng</dc:creator>
      <dc:date>2021-06-11T16:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747405#M234576</link>
      <description>&lt;P&gt;You can do a FILENAME My_File PIPE "ls -l *.cpt";&amp;nbsp; Again, though, I'm not sure that "L" is the best option.&amp;nbsp; I think there's an option that is going to just give you the filenames without the size, date, etc.&amp;nbsp; I'm just not remembering which option that is.&amp;nbsp; Let me see if I can work up a little example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 16:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747405#M234576</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-11T16:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747414#M234580</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/384908"&gt;@otteheng&lt;/a&gt;&amp;nbsp;is working off the CAS file service, so UNIX commands won't help here.&lt;/P&gt;
&lt;P&gt;I don't know if CAS provides functions analog to DOPEN, DNUM and DREAD for the file service.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 17:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747414#M234580</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-11T17:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747416#M234582</link>
      <description>&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0js70lrkxo6uvn1fl4a5aafnlgt.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0js70lrkxo6uvn1fl4a5aafnlgt.htm&lt;/A&gt;&lt;BR /&gt;See the documentation I linked to, again not sure if it will work with CAS but if you have a pattern it's quite straightforward.</description>
      <pubDate>Fri, 11 Jun 2021 17:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747416#M234582</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-11T17:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747421#M234587</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, can a SAS dataset be created apart from CAS and then the SAS dataset brought in?&amp;nbsp; The FILENAME PIPE is such a useful tool that it will be hard to part with when our shop switches to Viya -- if indeed there is no way to use it.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example from Windows, below.&amp;nbsp; I'm searching for .log files, but any file extension could be substituted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME	My_File	PIPE	"dir I:\commercial\production\OPSI\logs\sub_process_logs /a-d /b *.log";

DATA	My_Files;
	INFILE	My_File	TRUNCOVER;
	INPUT	Filename	$CHAR512.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 17:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747421#M234587</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-11T17:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Loop over all .cpt files in a directory and export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747478#M234606</link>
      <description>&lt;P&gt;I see nothing in the documentation that says PIPE does not work in CAS, but I don't know how/if you can access the physical filesystem, or if SAS Studio for Viya can be made to upload files to a physical location instead of a place in the file service.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 20:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-over-all-cpt-files-in-a-directory-and-export/m-p/747478#M234606</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-11T20:12:10Z</dc:date>
    </item>
  </channel>
</rss>

