<?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 How to subset on columns that start with a particular character in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783085#M249652</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I am looking a way to create a subset on all columns name that "start with" a specific character. My data contains the same column name multiple time with a digit number at the end and I want the code to always select all the columns regardless the last digit numbers and give the filter criteria on all the columns together .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AP22_0-1638264349529.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66241i8ED4C8B782A565F1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AP22_0-1638264349529.png" alt="AP22_0-1638264349529.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So here from the above table , I want only those observations where any of these columns starting with "apple" contains "one" .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Nov 2021 09:26:22 GMT</pubDate>
    <dc:creator>AP22</dc:creator>
    <dc:date>2021-11-30T09:26:22Z</dc:date>
    <item>
      <title>How to subset on columns that start with a particular character in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783085#M249652</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am looking a way to create a subset on all columns name that "start with" a specific character. My data contains the same column name multiple time with a digit number at the end and I want the code to always select all the columns regardless the last digit numbers and give the filter criteria on all the columns together .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AP22_0-1638264349529.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66241i8ED4C8B782A565F1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AP22_0-1638264349529.png" alt="AP22_0-1638264349529.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So here from the above table , I want only those observations where any of these columns starting with "apple" contains "one" .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 09:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783085#M249652</guid>
      <dc:creator>AP22</dc:creator>
      <dc:date>2021-11-30T09:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset on columns that start with a particular character in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783086#M249653</link>
      <description>&lt;P&gt;Please do not supply example data in pictures, we can't use pictures in SAS code; do it with data steps with datalines, like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input no (apple1-apple5) ($);
datalines;
1 one two two two two
2 two tw two three two
;

proc transpose
  data=have
  out=long (rename=(col1=apple))
;
by no;
var apple:;
run;

data want_long;
merge
  long
  long (
    in=want
    keep=no apple
    rename=(apple=_apple)
    where=(_apple = "one")
  )
;
by no;
if want;
run;

proc transpose
  data=want_long
  out=want_wide (drop=_name_)
;
by no;
var apple;
id _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will most probably find that the long layout (created by the first TRANSPOSE) is better for your work with data. Also see Maxim 19.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 09:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783086#M249653</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-30T09:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset on columns that start with a particular character in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783105#M249664</link>
      <description>&lt;P&gt;Here is an array solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                        
  set have;                       
  array apples(*) apple1-apple5;  
  do _N_=1 to dim(apples);        
    if apples(_N_)=:'one' then do;
      output;                     
      leave;                      
      end;                        
    end;                          
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have various datasets, with different numbers of "apples", you can change the array declaration to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array apples(*) apple:;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as long as no other columns have names that begin with "apple".&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 12:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-on-columns-that-start-with-a-particular-character/m-p/783105#M249664</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-30T12:01:20Z</dc:date>
    </item>
  </channel>
</rss>

