<?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: Converting XPT to SAS and change dataset name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463484#M284948</link>
    <description>&lt;P&gt;1. Do not recreate a table just to rename it. Use proc datasets&lt;/P&gt;
&lt;P&gt;2. proc port =&amp;gt; create XPT file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc cimport =&amp;gt; read XPT file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc copy =&amp;gt; copy data sets&lt;/P&gt;</description>
    <pubDate>Sat, 19 May 2018 04:52:25 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-05-19T04:52:25Z</dc:date>
    <item>
      <title>Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463085#M284941</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have at least 10 XPT files that I want to convert to SAS. It is easy. However, I realize that all datasets ended up with the same name in SAS. One way to do it is to create 10 different paths for these SAS files. But I wonder there is a way to change the dataset name while converting XPT to SAS so that I can store all datasets in one folder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 18:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463085#M284941</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-17T18:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463126#M284942</link>
      <description>&lt;P&gt;If you can use proc datasets, rather than proc copy, I'd think you can incorporate both of that proc's change and copy statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 19:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463126#M284942</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-17T19:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463202#M284943</link>
      <description>&lt;P&gt;We need a lot more information. For example what type of export files are you working with?&amp;nbsp; Those made with the XPORT engine or those made with PROC CPORT?&lt;/P&gt;
&lt;P&gt;Does each "XPT" file contain only one dataset?&amp;nbsp; Both the XPORT and CPORT formats allow for multiple datasets to appear in the same physical file.&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 02:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463202#M284943</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-18T02:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463206#M284944</link>
      <description>&lt;P&gt;Just run 2 procedures instead of one for each table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cimport data=DEST.TABLE infile=XPT1; run;
proc datasets lib=DEST; change TABLE=TABLE1; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It won't run any slower.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 03:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463206#M284944</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-18T03:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463394#M284945</link>
      <description>&lt;P&gt;I'm not sure how to use proc datasets to convert XPT to SAS. Can you give me an example?&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463394#M284945</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-18T16:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463395#M284946</link>
      <description>&lt;P&gt;So I was trying to convert multiple XPT files in one folder into SAS datasets using the macro below. And I used proc copy basically. Because all XPT files ended up with the same name, I only one SAS dataset after running the macro. But I finally was able to understand the macro and added a data step in the macro to change each dataset's name. It worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Macro using PROC COPY and the XPORT engine for reading transport files*/&lt;BR /&gt;%macro drive(dir,ext,out);&lt;BR /&gt;&lt;BR /&gt;%let filrf=mydir;&lt;BR /&gt;&lt;BR /&gt;/* Assigns the fileref of mydir to the directory and opens the directory */&lt;BR /&gt;%let rc=%sysfunc(filename(filrf,&amp;amp;dir));&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;BR /&gt;&lt;BR /&gt;/* Returns the number of members in the directory */&lt;BR /&gt;%let memcnt=%sysfunc(dnum(&amp;amp;did));&lt;BR /&gt;&lt;BR /&gt;/* Loops through entire directory */&lt;BR /&gt;%do i = 1 %to &amp;amp;memcnt;&lt;BR /&gt;&lt;BR /&gt;/* Returns the extension from each file */&lt;BR /&gt;%let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);&lt;BR /&gt;&lt;BR /&gt;/* Checks to see if file contains an extension */&lt;BR /&gt;%if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;ext) %then %do;&lt;BR /&gt;&lt;BR /&gt;/* Checks to see if the extension matches the parameter value */&lt;BR /&gt;/* If condition is true, submit PROC COPY statement */&lt;BR /&gt;%if (%superq(ext) ne and %qupcase(&amp;amp;name) = %qupcase(&amp;amp;ext)) or&lt;BR /&gt;(%superq(ext) = and %superq(name) ne) %then %do;&lt;BR /&gt;&lt;BR /&gt;libname old xport "&amp;amp;dir.\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))";&lt;BR /&gt;libname new "&amp;amp;out";&lt;BR /&gt;proc copy in=old out=new;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data new.CNTY&amp;amp;i;&lt;BR /&gt;set new.trnsport;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;/* Close the directory */&lt;BR /&gt;%let rc=%sysfunc(dclose(&amp;amp;did));&lt;BR /&gt;/* END MACRO */&lt;BR /&gt;%mend drive;&lt;/P&gt;&lt;P&gt;/* Macro call */&lt;/P&gt;&lt;P&gt;/*First parameter is the source folder, the second parameter is extension being */&lt;BR /&gt;/*searched for, and the third parameter is the target directory for the */&lt;BR /&gt;/*converted files. */&lt;/P&gt;&lt;P&gt;%drive(C:\temp,xpt,C:\temp\)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you mentioned proc cport, what is the difference between proc copy and proc cport?&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463395#M284946</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-18T16:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463396#M284947</link>
      <description>&lt;P&gt;Please see my reply to Tom. I know it's not going to take much time to add one more step, but I wasn't able to understand the macro in the beginning. But yes I edited the macro and added one more step and was able to change names now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you mentioned proc cimport, can you enlighten me on the differences among proc copy, cport, and cimport?&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 16:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463396#M284947</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-18T16:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463484#M284948</link>
      <description>&lt;P&gt;1. Do not recreate a table just to rename it. Use proc datasets&lt;/P&gt;
&lt;P&gt;2. proc port =&amp;gt; create XPT file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc cimport =&amp;gt; read XPT file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc copy =&amp;gt; copy data sets&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 04:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463484#M284948</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-19T04:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463500#M284949</link>
      <description>&lt;P&gt;You are using the XPORT libname engine to access SAS V5 Transport files.&amp;nbsp; That is the most portable of the SAS transport formats because it's structure is published.&amp;nbsp; But it has limitations of only supporting datasets that conform to the V5 structure.&amp;nbsp; (8 character variable and member names and 200 character variables).&amp;nbsp; There are also SAS macros that can read/write a newer SAS V8 transport files that support longer names and longer character variables.&amp;nbsp; The CPORT and CIMPORT procs create a different transport format. That format will allow you to transfer catalogs in addition to datasets.&amp;nbsp; But that format is not published and is also not backwards compatible.&amp;nbsp; You can't read a transport file made a newer version of SAS using an old version of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can simplify your macro a little. First you can move the libname statement that create the NEW libref out of the loop as it is not changing.&amp;nbsp; Then you can eliminate the PROC COPY step and just read the dataset from transport file directly with a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname old xport "&amp;amp;dir.\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))";
data new.CNTY&amp;amp;i;
set old.trnsport;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Are you sure that all of the transport files contain a TRNSPORT dataset?&amp;nbsp; Do any of them have more than one dataset in them?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can make your macro more flexible by reading the metadata from your transport files.&amp;nbsp; &amp;nbsp;You can use PROC CONTENTS on the NEW libref or query the DICTIONARY metadata tables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 12:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/463500#M284949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-19T12:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464432#M284950</link>
      <description>&lt;P&gt;Thanks a lot, Tom! I'm sure all transport files contain a trnsport dataset because when I open the xptfile library in SAS, there is only one trnsport dataset in there.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 16:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464432#M284950</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-23T16:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464434#M284951</link>
      <description>&lt;P&gt;Thanks, Chris! I agree that proc datasets is better than data step here.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 16:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464434#M284951</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-23T16:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XPT to SAS and change dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464443#M284952</link>
      <description>&lt;P&gt;Please ignore my previous reply. You're right. Not all transport files contain a trnsport dataset - some of them do, others have different names. Thank you for pointing it out!&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 16:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XPT-to-SAS-and-change-dataset-name/m-p/464443#M284952</guid>
      <dc:creator>Chengyiw</dc:creator>
      <dc:date>2018-05-23T16:27:31Z</dc:date>
    </item>
  </channel>
</rss>

