<?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: Copy dataset from one library to another based on dataset name prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716033#M221228</link>
    <description>proc copy in=library_all  out=library_a ;&lt;BR /&gt; select a_: ;&lt;BR /&gt;run;&lt;BR /&gt;proc copy in=library_all  out=library_b ;&lt;BR /&gt; select b_: ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;And Make a macro to go through all the table .</description>
    <pubDate>Tue, 02 Feb 2021 12:01:51 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-02-02T12:01:51Z</dc:date>
    <item>
      <title>Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715990#M221208</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need to copy the dataset from one library to another but it is based on the prefix of the dataset name.&lt;/P&gt;
&lt;P&gt;For example; I have library “Libref_all” and I have below datasets in this library,&lt;/P&gt;
&lt;TABLE width="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Libref_all&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;A_DM1.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;A_DM2.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;A_DM3.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;A_DM4.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;B_DM1.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;B_DM2.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;B_DM3.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;B_DM4.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;C_DM1.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;C_DM2.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;
&lt;P&gt;D_DM1.sas7bdat&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to move these datasets based on their names, like dataset having prefix “A_” should copy to “Libref_A” library, similarly “B_” should copy to “Libref_b”, “C_” should copy to “Libref_C” and “D_” should copy to “Libref_D”.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 10:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715990#M221208</guid>
      <dc:creator>Soham0707</dc:creator>
      <dc:date>2021-02-02T10:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715993#M221210</link>
      <description>&lt;P&gt;Try this. This builds a Proc Copy call for each obs. You can see the call in the data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Uncomment the Call Execute part and see if it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Libref_all $20.;
datalines;
A_DM1.sas7bdat
A_DM2.sas7bdat
A_DM3.sas7bdat
A_DM4.sas7bdat
B_DM1.sas7bdat
B_DM2.sas7bdat
B_DM3.sas7bdat
B_DM4.sas7bdat
C_DM1.sas7bdat
C_DM2.sas7bdat
D_DM1.sas7bdat
;

data callstack;
   set have;
   ds = scan(Libref_all, 1);
   lb = cats("Libref_", char(Libref_all, 1));

   call = compbl(cat(
      "proc copy in = Libref_all out = ", lb, "memtype=data;
          select ", ds, ";
       run;"
    ));
  *call execute (call);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2021 10:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715993#M221210</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-02T10:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715994#M221211</link>
      <description>&lt;P&gt;If you have datasets listed like you presented, you could try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
input Libref_all $ 20.;

call execute(
"data Libref_" !! scan(Libref_all,1,"_") !! '.' !! scan(Libref_all,1,".") !! "; "
!! "set Libref_all." !! scan(Libref_all,1,".") !! "; run;"
!! "proc delete data = Libref_all." !! scan(Libref_all,1,".") !! "; run;"
);

cards;
A_DM1.sas7bdat
A_DM2.sas7bdat
A_DM3.sas7bdat
A_DM4.sas7bdat
B_DM1.sas7bdat
B_DM2.sas7bdat
B_DM3.sas7bdat
B_DM4.sas7bdat
C_DM1.sas7bdat
C_DM2.sas7bdat
D_DM1.sas7bdat
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the `call execute()` will produce the code for you. I'm assuming you don't have any indexes and datasets aren't compressed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 10:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/715994#M221211</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-02-02T10:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716009#M221220</link>
      <description>Thanks PeterClemmensen.&lt;BR /&gt;&lt;BR /&gt;I have more than 1000 datasets to copy based on the name. Is there any other way to do this without datalines or cards statement?&lt;BR /&gt;I have provided an example that describes the scenario.&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Feb 2021 10:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716009#M221220</guid>
      <dc:creator>Soham0707</dc:creator>
      <dc:date>2021-02-02T10:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716020#M221221</link>
      <description>&lt;P&gt;The code will work without the Datalines/Cards Statement. They are purely for demonstration.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try running the code against your actual data and check the callstack data. Does the call variable contain Proc Copy steps that look alright?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, try uncommenting the Call Execute Statement and see what happens.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 11:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716020#M221221</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-02T11:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716033#M221228</link>
      <description>proc copy in=library_all  out=library_a ;&lt;BR /&gt; select a_: ;&lt;BR /&gt;run;&lt;BR /&gt;proc copy in=library_all  out=library_b ;&lt;BR /&gt; select b_: ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;And Make a macro to go through all the table .</description>
      <pubDate>Tue, 02 Feb 2021 12:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716033#M221228</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-02T12:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Copy dataset from one library to another based on dataset name prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716042#M221232</link>
      <description>Thank you so much Ksharp. it's working.</description>
      <pubDate>Tue, 02 Feb 2021 12:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-dataset-from-one-library-to-another-based-on-dataset-name/m-p/716042#M221232</guid>
      <dc:creator>Soham0707</dc:creator>
      <dc:date>2021-02-02T12:30:01Z</dc:date>
    </item>
  </channel>
</rss>

