<?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: Need help with dropping a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862587#M340731</link>
    <description>&lt;P&gt;You can use a variable name prefix to drop variables, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mergepart (drop=Street: ) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will drop any variables that start with Street (case insensitive).&lt;/P&gt;</description>
    <pubDate>Mon, 06 Mar 2023 22:25:18 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-03-06T22:25:18Z</dc:date>
    <item>
      <title>Need help with dropping a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862585#M340730</link>
      <description>&lt;P&gt;Hi, I am working on a project and I have to drop any variable where the variable name begins with ‘Street’ in this merge data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my syntax:&lt;/P&gt;&lt;P&gt;libname bhadlibs 'C:\Users\PhotonUser\My Files\Temporary Files';&lt;BR /&gt;data bhadlibs.employee_payroll;&lt;BR /&gt;set bhadlibs.employeepayroll;&lt;BR /&gt;proc sort;by employee_id;&lt;/P&gt;&lt;P&gt;/* Experienced difficulty on renaming multiple naming conventions and dropping "street. We should review this in class.&lt;BR /&gt;data bhadlibs.employee_donations;&lt;BR /&gt;set bhadlibs.employee_donations;&lt;BR /&gt;proc sort;by employee_id;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data bhadlibs.employee_addresses (rename=(street_id=street));&lt;BR /&gt;set bhadlibs.employee_addresses;&lt;BR /&gt;proc sort;by employee_id;&lt;/P&gt;&lt;P&gt;data bhadlibs.employee_addresses (rename=(street_number=street));&lt;BR /&gt;set bhadlibs.employee_addresses;&lt;BR /&gt;proc sort;by employee_id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data bhadlibs.employee_addresses (rename=(street_name=street2));&lt;BR /&gt;set bhadlibs.employee_addresses;&lt;BR /&gt;proc sort;by employee_id;&lt;BR /&gt;run;*/&lt;/P&gt;&lt;P&gt;data bhadlibs.employee_addresses;&lt;BR /&gt;set bhadlibs.employee_addresses2 (drop=street);&lt;BR /&gt;footnote1 'confidential';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mergepart;&lt;BR /&gt;merge bhadlibs.employee_payroll bhadlibs.employee_donations bhadlibs.employee_addresses;&lt;BR /&gt;by employee_id;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 22:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862585#M340730</guid>
      <dc:creator>Jmitchell</dc:creator>
      <dc:date>2023-03-06T22:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dropping a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862587#M340731</link>
      <description>&lt;P&gt;You can use a variable name prefix to drop variables, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mergepart (drop=Street: ) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will drop any variables that start with Street (case insensitive).&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 22:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862587#M340731</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-06T22:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dropping a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862588#M340732</link>
      <description>&lt;P&gt;Interesting, you say you want to drop any variable whose name begins with 'street', but then you don't do anything like that, there are no DROP statements or options anywhere in your code until the very end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Furthermore, this is highly redundant and wastes your time and computer time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bhadlibs.employee_payroll;
set bhadlibs.employeepayroll;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;First, good practice in writing code means you should end each step with a RUN command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bhadlibs.employee_payroll;
set bhadlibs.employeepayroll;
run;
proc sort;by employee_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now also notice that your DATA step does not do anything. You had a dataset named BHADLIBS.EMPLOYEEPAYROLL and you create a brand new dataset where nothing changes except the name, which is now BHADLIBS.EMPLOYEE_PAYROLL. Data steps with nothing but a SET statement are generally not worth doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about this to drop variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bhadlibs.employee_payroll;
    set bhadlibs.employeepayroll(drop=street:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice variables are dropped in the SET statement (so its not just a SET statement now, it is a SET statement with a drop). The &lt;FONT face="courier new,courier"&gt;drop=street:&lt;/FONT&gt; (note the colon after street) indicates that all variables whose name begins with &lt;FONT face="courier new,courier"&gt;street&lt;/FONT&gt; are now dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or to simplify the entire thing into one data step, try this (which will require PROC SORTs before it can work)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mergepart;
    merge bhadlibs.employee_payroll bhadlibs.employee_donations bhadlibs.employee_addresses;
    by id;
    drop street:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2023 22:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862588#M340732</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-06T22:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dropping a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862590#M340734</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I'm still getting an error message. But I think there are a couple of other&lt;BR /&gt;issues. I keep getting an error saying my file doesn't exist.&lt;BR /&gt;&lt;BR /&gt;How do I correct this?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Mar 2023 23:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862590#M340734</guid>
      <dc:creator>Jmitchell</dc:creator>
      <dc:date>2023-03-06T23:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with dropping a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862616#M340740</link>
      <description>&lt;P&gt;Please post the complete log (all code and messages) of the failing step by copy/pasting it into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 06:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-dropping-a-variable/m-p/862616#M340740</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-07T06:10:52Z</dc:date>
    </item>
  </channel>
</rss>

