<?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: using the xpt2loc macro to convert multiple .xpt files to sas datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/789991#M252890</link>
    <description>&lt;P&gt;Thank you so much. The single quote in macro is confusion.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jan 2022 14:12:35 GMT</pubDate>
    <dc:creator>ahaoya</dc:creator>
    <dc:date>2022-01-13T14:12:35Z</dc:date>
    <item>
      <title>using the xpt2loc macro to convert multiple .xpt files to sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591457#M169422</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; have multiple .xpt files (v8) created using the loc2xpt macro which I need&amp;nbsp; to convert to sas files using the xpt2loc macro.&amp;nbsp; I am new to sas but I have managed to use the macro to convert a single file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%xpt2loc ( libref   = work, memlist  = _all_ , filespec = 'c:/myfile.xpt') &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However I cannot loop through a directory and select all the .xpt file names to use in the filespec. I have trying to adapt the code below which I have found on these boards&amp;nbsp; but so far have been unsuccessful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\XPT Datasets;
filename xptfiles pipe "dir /b ""&amp;amp;path\%str(*).xpt"" " ;
filename code temp;
data files;
  infile xptfiles truncover;
  input filename $100. ;
  file code;
  put 'filename xptfile "&amp;amp;path\' filename +(-1) '" access=readonly;';
   put 'proc copy inlib=xptfile outlib=sasfile; run;' ;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 10:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591457#M169422</guid>
      <dc:creator>David20</dc:creator>
      <dc:date>2019-09-25T10:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: using the xpt2loc macro to convert multiple .xpt files to sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591652#M169538</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292223"&gt;@David20&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first of the two PUT statements in your code is not correct. It should rather look like this:&lt;/P&gt;
&lt;PRE&gt;put '&lt;FONT color="#FF0000"&gt;lib&lt;/FONT&gt;name xptfile &lt;FONT color="#FF0000"&gt;xport&lt;/FONT&gt; "&amp;amp;path\' filename +(-1) '" access=readonly;';&lt;/PRE&gt;
&lt;P&gt;Also, make sure that &lt;FONT face="courier new,courier"&gt;sasfile&lt;/FONT&gt; (which is a libref used in your PROC COPY statement) points to the destination folder of the SAS datasets to be created, e.g., with a LIBNAME statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname sasfile 'C:\Temp';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Replace &lt;FONT face="courier new,courier"&gt;C:\Temp&lt;/FONT&gt; by the correct path to the existing destination folder.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the DATA step has produced the code file (consisting of LIBNAME and PROC COPY statements) you may want to look into that file (just to verify quickly that the produced code is syntactically correct), which will reside in your WORK library with a name like #LNxxxxx (where xxxxx is a number such as 00082). The full path will be shown in the log of the DATA step after the line&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#0000FF"&gt;NOTE: The file CODE is:&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Open the file with Notepad.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then "%include" (i.e. execute) the code file by submitting&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%inc code;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Alternatively&lt;/STRONG&gt;, you can combine the two approaches and produce a code file containing XPT2LOC macro calls (instead of&amp;nbsp;LIBNAME and PROC COPY statements). To do this, a single PUT statement would replace the two existing PUT statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put '%xpt2loc(libref = sasfile, memlist = _all_, filespec = ''' "&amp;amp;path" '\' filename +(-1) ''')';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(The other steps -- quick check of the code file and &lt;FONT face="courier new,courier"&gt;%inc&lt;/FONT&gt; statement -- are the same as above.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;In both cases&lt;/STRONG&gt; there is a &lt;STRONG&gt;potential issue&lt;/STRONG&gt;: Both the PROC COPY statements and the XPT2LOC macro calls would overwrite existing datasets with the same name in the destination folder without asking. This means, if two of the .xpt files happened to contain datasets with the same name, you would end up with the dataset from the second .xpt file. So, you should check the documentation of the .xpt files (if any) and the SAS log to make sure that this does not happen. (Otherwise, use different destination folders to avoid the name conflict.)&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 18:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591652#M169538</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-25T18:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: using the xpt2loc macro to convert multiple .xpt files to sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591686#M169549</link>
      <description>&lt;P&gt;It should be trivial to change that program to generate the code you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\XPT Datasets;
filename xptfiles pipe "dir /b ""&amp;amp;path\%str(*).xpt"" " ;
filename code temp;
data files;
  infile xptfiles truncover;
  input filename $100. ;
  file code;
  put '%xpt2loc(libref=work,memlist=_all_,filespec=' filename :$quote. ')' ; 
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 19:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591686#M169549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-25T19:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: using the xpt2loc macro to convert multiple .xpt files to sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591886#M169651</link>
      <description>&lt;P&gt;Many thanks for both of these replies. This has helped a lot and I have been able to adapt these to create a working solution using the XPT2LOC macro, as I believe the proc copy statement will not work with v8 transport files created with the LOC2XPT macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 15:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/591886#M169651</guid>
      <dc:creator>David20</dc:creator>
      <dc:date>2019-09-26T15:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: using the xpt2loc macro to convert multiple .xpt files to sas datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/789991#M252890</link>
      <description>&lt;P&gt;Thank you so much. The single quote in macro is confusion.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 14:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/using-the-xpt2loc-macro-to-convert-multiple-xpt-files-to-sas/m-p/789991#M252890</guid>
      <dc:creator>ahaoya</dc:creator>
      <dc:date>2022-01-13T14:12:35Z</dc:date>
    </item>
  </channel>
</rss>

