<?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: What is the best way to analyze numerous variables beginning with a specific text such as 'abc' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417185#M102473</link>
    <description>&lt;P&gt;You probably don't need to split them up even to do that see below.&amp;nbsp; However that being said it would really be a good idea to split them up, but in long form rather than wide:&lt;/P&gt;
&lt;PRE&gt;data want (keep=wrd);
  set have;
  length wrd $20;
  do i=1 to countw(original,",");
    wrd=scan(original,i,",");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;That is a far simpler and easier to work with data structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To show how to co it without changing:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select sum(count(ORIGINAL,"TT")) as WANT
  from   HAVE;
quit;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Nov 2017 19:10:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-29T19:10:03Z</dc:date>
    <item>
      <title>What is the best way to analyze numerous variables beginning with a specific text such as 'abc'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417094#M102467</link>
      <description>&lt;P&gt;I have a variable with numerous (and varying) number of elements within it that is separated by a delimiter (;) and the following code below creates new variables for each observation based on the number of elements. Now as I am working through my analysis I am only interested in analyzing variables within the newly created ~30 that begin with 'abc' and was hoping someone would provide insight into the best way to go about this using SAS 9.4. The intended outcome is to identify key text after the initial 'abc' as well as to determine if key text is missing after the initial 'abc.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Building an array without knowing the max number of variables;&lt;BR /&gt;*proc sql stores a macro variable to determine the number of elements in the string to be applied -&lt;BR /&gt;then the data step parses by the delimiter into the set amount determined by the proc sql step;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select max(count(original,';'))+1 into :maxelements from have;&lt;BR /&gt;Data&amp;nbsp;want (drop=i);&lt;BR /&gt;set have;&lt;BR /&gt;array parsed_vars $ new1-new%eval(&amp;amp;maxelements);&lt;BR /&gt;do i=1 to &amp;amp;maxelements;&lt;BR /&gt;parsed_vars(i)=scan(original,i,";");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417094#M102467</guid>
      <dc:creator>Keaton</dc:creator>
      <dc:date>2017-11-29T15:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to analyze numerous variables beginning with a specific text such as 'abc'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417099#M102468</link>
      <description>&lt;P&gt;Without seeing something in the way of data its hard to say.&amp;nbsp; The "best way" is subjective, you could for instance not create 30 observations, but output to rows, then utilise by grouping to analyse the data.&amp;nbsp; Or, if your variables have a common prefix you could use shortened versions:&lt;/P&gt;
&lt;PRE&gt;result=max(of var:);
&lt;/PRE&gt;
&lt;P&gt;Assumes all the new variables have a prefix of var.&amp;nbsp; Or you could use lists, var1--var10.&amp;nbsp; There are many methods, and I would certainly avoid going down the macro route until you absolutely have to.&amp;nbsp; Also, when posting a question, post test data in the form of a datastep - this helps us to see the data and the structure, just saying 30 elements is meaningless - could be number or character or any mix.&amp;nbsp; For instance if they are all number, _numeric_ is a quick way of referring to them.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417099#M102468</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T15:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to analyze numerous variables beginning with a specific text such as 'abc'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417110#M102469</link>
      <description>&lt;P&gt;Post some sample data and your expected output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175187"&gt;@Keaton&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a variable with numerous (and varying) number of elements within it that is separated by a delimiter (;) and the following code below creates new variables for each observation based on the number of elements. Now as I am working through my analysis I am only interested in analyzing variables within the newly created ~30 that begin with 'abc' and was hoping someone would provide insight into the best way to go about this using SAS 9.4. The intended outcome is to identify key text after the initial 'abc' as well as to determine if key text is missing after the initial 'abc.'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Building an array without knowing the max number of variables;&lt;BR /&gt;*proc sql stores a macro variable to determine the number of elements in the string to be applied -&lt;BR /&gt;then the data step parses by the delimiter into the set amount determined by the proc sql step;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select max(count(original,';'))+1 into :maxelements from have;&lt;BR /&gt;Data&amp;nbsp;want (drop=i);&lt;BR /&gt;set have;&lt;BR /&gt;array parsed_vars $ new1-new%eval(&amp;amp;maxelements);&lt;BR /&gt;do i=1 to &amp;amp;maxelements;&lt;BR /&gt;parsed_vars(i)=scan(original,i,";");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417110#M102469</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-29T15:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to analyze numerous variables beginning with a specific text such as 'abc'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417167#M102470</link>
      <description>&lt;P&gt;Thanks for the suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original dataset with original variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; &amp;nbsp; original&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AA456; TT3; BB345&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TT3X5&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AA234; BB35X; CC352&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parsed original variable into new variables as discussed in original post:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;obs&amp;nbsp; &amp;nbsp; original&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AA456; TT3; BB345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AA456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;TT3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BB345&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TT3X5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;TT3X5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AA234; BB35X; CC352&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;AA234&amp;nbsp; &amp;nbsp; &amp;nbsp;BB35X&amp;nbsp; &amp;nbsp;&amp;nbsp;CC352&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;..... &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The output is how many observations&amp;nbsp;have variables beginning with TT and&amp;nbsp;additionally have less than 4 characters.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 17:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417167#M102470</guid>
      <dc:creator>Keaton</dc:creator>
      <dc:date>2017-11-29T17:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to analyze numerous variables beginning with a specific text such as 'abc'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417185#M102473</link>
      <description>&lt;P&gt;You probably don't need to split them up even to do that see below.&amp;nbsp; However that being said it would really be a good idea to split them up, but in long form rather than wide:&lt;/P&gt;
&lt;PRE&gt;data want (keep=wrd);
  set have;
  length wrd $20;
  do i=1 to countw(original,",");
    wrd=scan(original,i,",");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;That is a far simpler and easier to work with data structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To show how to co it without changing:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select sum(count(ORIGINAL,"TT")) as WANT
  from   HAVE;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Nov 2017 19:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-best-way-to-analyze-numerous-variables-beginning/m-p/417185#M102473</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-29T19:10:03Z</dc:date>
    </item>
  </channel>
</rss>

