<?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: How do i Loop through the library and delete records in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551672#M9036</link>
    <description>&lt;P&gt;1) Remember to have backups you can return to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) The following code assumes the employee id column in each emp table can be identified as the only one containing 'emp' and 'id'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) It generates &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; statements for each table, at the moment they are just &lt;FONT face="courier new,courier"&gt;create table&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;select&lt;/FONT&gt; statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) Run the code produced in the&amp;nbsp;'full-file-path.sas'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5) If you are happy with the results then you can change the &lt;FONT face="courier new,courier"&gt;sql&lt;/FONT&gt; to use a &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt; statement instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* replace 'full-file-path.sas' and 'monthly_deletes' */
data _null_;
   file 'full-file-path.sas';

   set sashelp.vcolumn;

   where     upcase(libname) eq       'EMP'
         and upcase(name)    contains ('EMP')
         and upcase(name)    contains ('ID')  
   ;

   put 'proc sql;';
   put 'create table work.' memname 'as';
   put 'select * from emp.' memname;
   put 'where ' name 'in (select emp_id from monthly_deletes);';
   put 'quit;';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2019 12:24:16 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2019-04-17T12:24:16Z</dc:date>
    <item>
      <title>How do i Loop through the library and delete records</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551646#M9033</link>
      <description>&lt;P&gt;My requirement is to delete employee records from datasets in library (Emp) by scanning all the datasets (more than &lt;STRONG&gt;2000&lt;/STRONG&gt; datasets and&lt;/P&gt;&lt;P&gt;most of them are huge datasets with &lt;STRONG&gt;1 &lt;/STRONG&gt;million plus observations)&lt;STRONG&gt;.&lt;/STRONG&gt; Please note that not all datasets has Employee ID variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The list of Employee ID's to be deleted will be provided in a separate dataset every month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This dataset has one variable Emp_ID which is $9. and 9 length.&lt;/P&gt;&lt;P&gt;The issue is in the library Emp which has different name and lengths for the same variable in different datasets.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Emp.Address_mon dataset has Employee_ID.&lt;/P&gt;&lt;P&gt;Emp.Trans_mon has EmpID&lt;/P&gt;&lt;P&gt;Emp.Contact_mon has Emp_ID ans so on.&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;How do I loop through and scan the Emp_ID in the library using macros and delete the record in a efficient way.&lt;/P&gt;&lt;P&gt;Any suggestions&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 11:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551646#M9033</guid>
      <dc:creator>anandrc</dc:creator>
      <dc:date>2019-04-17T11:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do i Loop through the library and delete records</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551672#M9036</link>
      <description>&lt;P&gt;1) Remember to have backups you can return to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) The following code assumes the employee id column in each emp table can be identified as the only one containing 'emp' and 'id'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) It generates &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; statements for each table, at the moment they are just &lt;FONT face="courier new,courier"&gt;create table&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;select&lt;/FONT&gt; statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) Run the code produced in the&amp;nbsp;'full-file-path.sas'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5) If you are happy with the results then you can change the &lt;FONT face="courier new,courier"&gt;sql&lt;/FONT&gt; to use a &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt; statement instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* replace 'full-file-path.sas' and 'monthly_deletes' */
data _null_;
   file 'full-file-path.sas';

   set sashelp.vcolumn;

   where     upcase(libname) eq       'EMP'
         and upcase(name)    contains ('EMP')
         and upcase(name)    contains ('ID')  
   ;

   put 'proc sql;';
   put 'create table work.' memname 'as';
   put 'select * from emp.' memname;
   put 'where ' name 'in (select emp_id from monthly_deletes);';
   put 'quit;';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 12:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551672#M9036</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-04-17T12:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do i Loop through the library and delete records</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551758#M9044</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183450"&gt;@anandrc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My requirement is to delete employee records from datasets in library (Emp) by scanning all the datasets (more than &lt;STRONG&gt;2000&lt;/STRONG&gt; datasets and&lt;/P&gt;
&lt;P&gt;most of them are huge datasets with &lt;STRONG&gt;1 &lt;/STRONG&gt;million plus observations)&lt;STRONG&gt;.&lt;/STRONG&gt; Please note that not all datasets has Employee ID variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The list of Employee ID's to be deleted will be provided in a separate dataset every month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This dataset has one variable Emp_ID which is $9. and 9 length.&lt;/P&gt;
&lt;P&gt;The issue is in the library Emp which has&lt;FONT color="#0000ff"&gt;&lt;STRONG&gt; different name and lengths&lt;/STRONG&gt;&lt;/FONT&gt; for the same variable in different datasets.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Emp.Address_mon dataset has Employee_ID.&lt;/P&gt;
&lt;P&gt;Emp.Trans_mon has EmpID&lt;/P&gt;
&lt;P&gt;Emp.Contact_mon has Emp_ID ans so on.&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;How do I loop through and scan the Emp_ID in the library using macros and delete the record in a efficient way.&lt;/P&gt;
&lt;P&gt;Any suggestions&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say the first step is to go back and 1) change everything creating /using different names to the same variable name and 2) make sure the lengths are consistent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you will have to create an maintain an additional table of which data set uses which name. If you have thousands of data sets I suspect that you may have more with different variable names appearing frequently.&lt;/P&gt;
&lt;P&gt;If the length differences are actually using different values such as 12-345 in one set and 12-345-7896 in a different one then you have a whole bunch of other rules to maintain to come close to this. If the values aren't different that should not be an issue &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;unless&lt;/STRONG&gt;&lt;/FONT&gt; some are actually numeric and others are actually character. That will cause another different class of headaches as you will need somewhat different code to handle those as two different approaches.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 14:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551758#M9044</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-17T14:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do i Loop through the library and delete records</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551769#M9047</link>
      <description>Thanks Amir. I did test this on a sample library of 10 datasets and it works. Will need to test this on the entire library and take a not on the processing time</description>
      <pubDate>Wed, 17 Apr 2019 15:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-i-Loop-through-the-library-and-delete-records/m-p/551769#M9047</guid>
      <dc:creator>anandrc</dc:creator>
      <dc:date>2019-04-17T15:21:37Z</dc:date>
    </item>
  </channel>
</rss>

