<?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 to drop or keep variables if...??? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530787#M5805</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258374"&gt;@Zach84&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset that has variables named Amin to Amax. E.g. A121, A122 up to A314. min and max are created in some procedure before. I would like automatically to do the following&lt;/P&gt;
&lt;P&gt;1) to keep variables greater than e.g. A150 i.e. A150, A151, up to A(max(xx)) i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data newdata;&lt;/P&gt;
&lt;P&gt;set olddata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep A150-Amax;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) drop all above e.g. A180 i.e. keep Amin - A180 i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data newdata;&lt;/P&gt;
&lt;P&gt;set olddata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep Amin-A180;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For variables that have actual numbers as part of the name then: Keep A120 - A180 is fine.&lt;/P&gt;
&lt;P&gt;But character values seldom sort properly to include in a list. So if you have an actual name like Amax then including that in a list is likely not going to be greatly helpful. If you don't know what the lowest or largest index is and need to use something like A20 we'll need to add a step to identify that and is likely going to be some additional code involved that may require sharing more about your actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables are sequential in the data then you can use a keep or drop with two dashes when the names are not as nice but are in column order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A list like: Keep thisvar -- thatvar will keep all of the variables in order.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Jan 2019 21:02:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-01-28T21:02:50Z</dc:date>
    <item>
      <title>How to drop or keep variables if...???</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530774#M5803</link>
      <description>&lt;P&gt;I have a dataset that has variables named Amin to Amax. E.g. A121, A122 up to A314. min and max are created in some procedure before. I would like automatically to do the following&lt;/P&gt;&lt;P&gt;1) to keep variables greater than e.g. A150 i.e. A150, A151, up to A(max(xx)) i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data newdata;&lt;/P&gt;&lt;P&gt;set olddata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep A150-Amax;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) drop all above e.g. A180 i.e. keep Amin - A180 i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data newdata;&lt;/P&gt;&lt;P&gt;set olddata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep Amin-A180;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 20:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530774#M5803</guid>
      <dc:creator>Zach84</dc:creator>
      <dc:date>2019-01-28T20:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to drop or keep variables if...???</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530787#M5805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258374"&gt;@Zach84&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset that has variables named Amin to Amax. E.g. A121, A122 up to A314. min and max are created in some procedure before. I would like automatically to do the following&lt;/P&gt;
&lt;P&gt;1) to keep variables greater than e.g. A150 i.e. A150, A151, up to A(max(xx)) i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data newdata;&lt;/P&gt;
&lt;P&gt;set olddata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep A150-Amax;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) drop all above e.g. A180 i.e. keep Amin - A180 i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data newdata;&lt;/P&gt;
&lt;P&gt;set olddata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep Amin-A180;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For variables that have actual numbers as part of the name then: Keep A120 - A180 is fine.&lt;/P&gt;
&lt;P&gt;But character values seldom sort properly to include in a list. So if you have an actual name like Amax then including that in a list is likely not going to be greatly helpful. If you don't know what the lowest or largest index is and need to use something like A20 we'll need to add a step to identify that and is likely going to be some additional code involved that may require sharing more about your actual data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables are sequential in the data then you can use a keep or drop with two dashes when the names are not as nice but are in column order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A list like: Keep thisvar -- thatvar will keep all of the variables in order.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 21:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530787#M5805</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-28T21:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to drop or keep variables if...???</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530788#M5806</link>
      <description>&lt;P&gt;something like below using dictionary.columns or much simpler and cleaner by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array A (150) (1000:1149);
run;

/* drop variables macrovariable */
proc sql;
select name into :var seperated by " " from dictionary.columns
where memname ="HAVE"
and libname ="WORK"
and input(compress(name,,"kd"),best32.) ge 45 and input(compress(name,,"kd"),best32.) le 145;

/* drop variables */
data want;
set have (drop= &amp;amp;var);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 21:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-drop-or-keep-variables-if/m-p/530788#M5806</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2019-01-28T21:04:56Z</dc:date>
    </item>
  </channel>
</rss>

