<?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: Calculation from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464398#M118396</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;INDEX function returns the position of the first occurrence of the string’s first character.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need a different thing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need to know in which position &amp;nbsp; (1 until 12) was first failure (value11)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 7 8 9 10 9 11 11 11 11 10 11 9 &amp;nbsp; &amp;nbsp;(Here the answer is 7)&lt;BR /&gt;2 8 8 7 7 7 7 6 7 7 8 7 11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 12)&lt;BR /&gt;3 3 3 3 3 2 2 2 3 3 3 2 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;BR /&gt;4 . . . . . . 0 0 0 0 6 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If these values are numeric and you will be numeric calculations later I strongly suggest looking at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s array approach.&lt;/P&gt;
&lt;P&gt;An alternate of&amp;nbsp;finding first value would be the WHICHN function (referencing Patricks array definition)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First11 = whichn(11, of scores(*));&lt;/P&gt;
&lt;P&gt;which does return 0 when the value in the first position is not found in any of the array elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 May 2018 14:39:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-05-23T14:39:18Z</dc:date>
    <item>
      <title>Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464287#M118361</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am working in a bank.&lt;/P&gt;&lt;P&gt;We have a data set with&amp;nbsp;scores information for every customer.&lt;/P&gt;&lt;P&gt;Score for each customer can be any integer between 0 to 11.(11 is a failure status).&lt;/P&gt;&lt;P&gt;I created a vector of last 12 scores for each customer(with comma between values).&lt;/P&gt;&lt;P&gt;I have 3 questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question1-Calculate How many non-missing arguments&amp;nbsp;exits in the vector.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are 12&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question2&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Calculate&amp;nbsp;&lt;SPAN&gt;How many missing+non-missing&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;arguments&amp;nbsp;exits in the vector.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are 12&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question3-Calculate&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;How many&amp;nbsp;&amp;nbsp;times 11 appear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question&lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Calculate location of first failure(11)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp;&amp;nbsp;Here we need to get:6&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; Here we need to get:0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data tbl1;&lt;BR /&gt;input ID Score1 Score2 Score3 Score4 Score5 Score6&lt;BR /&gt;Score7 Score8 Score9 Score10 Score11 Score12;&lt;BR /&gt;cards;&lt;BR /&gt;1 7 8 9 10 9 11 11 11 11 10 11 9&lt;BR /&gt;2 8 8 7 7 7 7 6 7 7 8 7 8&lt;BR /&gt;3 3 3 3 3 2 2 2 3 3 3 2 2&lt;BR /&gt;3 . . . . . 0 0 0 0 6 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;BR /&gt;length ScoreVector1 ScoreVector2 ScoreVector3 ScoreVector4 $32.;&lt;BR /&gt;set &lt;SPAN&gt;tbl1&lt;/SPAN&gt;;&lt;BR /&gt;ScoreVector1=compress(Score1)||','|| compress(Score1)||','|| compress(Score3)&lt;BR /&gt;||','|| compress(Score4)||','|| compress(Score5)||','|| compress(Score6)&lt;BR /&gt;||','|| compress(Score7)||','|| compress(Score8)||','|| compress(Score9)&lt;BR /&gt;||','|| compress(Score10)||','|| compress(Score11)||','|| compress(Score12);&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 06:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464287#M118361</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-23T06:15:42Z</dc:date>
    </item>
    <item>
      <title>calculations from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464288#M118364</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am working in a bank.&lt;/P&gt;&lt;P&gt;We have a data set with&amp;nbsp;scores information for every customer.&lt;/P&gt;&lt;P&gt;Score for each customer can be any integer between 0 to 11.(11 is a failure status).&lt;/P&gt;&lt;P&gt;I created a vector of last 12 scores for each customer(with comma between values).&lt;/P&gt;&lt;P&gt;I have 3 questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question1-Calculate How many non-missing arguments&amp;nbsp;exits in the vector.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are 12&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question2&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Calculate&amp;nbsp;&lt;SPAN&gt;How many missing+non-missing&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;arguments&amp;nbsp;exits in the vector.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are 12&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question3-Calculate&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;How many&amp;nbsp;&amp;nbsp;times 11 appear&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; &amp;nbsp; Here there are&amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question&lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Calculate location of first failure(11)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;7,7,9,10,9,11,11,11,11,10,11,9 &amp;nbsp; &amp;nbsp;&amp;nbsp;Here we need to get:6&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3,.,.,.,.,.,0,0,0,0,6,7 &amp;nbsp; Here we need to get:0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data tbl1;&lt;BR /&gt;input ID Score1 Score2 Score3 Score4 Score5 Score6&lt;BR /&gt;Score7 Score8 Score9 Score10 Score11 Score12;&lt;BR /&gt;cards;&lt;BR /&gt;1 7 8 9 10 9 11 11 11 11 10 11 9&lt;BR /&gt;2 8 8 7 7 7 7 6 7 7 8 7 8&lt;BR /&gt;3 3 3 3 3 2 2 2 3 3 3 2 2&lt;BR /&gt;3 . . . . . 0 0 0 0 6 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data tbl2;&lt;BR /&gt;length &amp;nbsp;&lt;SPAN&gt;ScoreVector&lt;/SPAN&gt;&amp;nbsp; $32.;&lt;BR /&gt;set &lt;SPAN&gt;tbl1&lt;/SPAN&gt;;&lt;BR /&gt;ScoreVector=compress(Score1)||','|| compress(Score1)||','|| compress(Score3)&lt;BR /&gt;||','|| compress(Score4)||','|| compress(Score5)||','|| compress(Score6)&lt;BR /&gt;||','|| compress(Score7)||','|| compress(Score8)||','|| compress(Score9)&lt;BR /&gt;||','|| compress(Score10)||','|| compress(Score11)||','|| compress(Score12);&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 06:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464288#M118364</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-23T06:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464291#M118365</link>
      <description>&lt;P&gt;In general, it is better to keep data points in their own variables.&amp;nbsp; In this instance it may actually help, but you could do the same thing with an array and catx, e.g:&lt;/P&gt;
&lt;PRE&gt;data want;
  length scorevector1 $2000;
  set tbl1;
  scorevector1=catx(',',score1,score2,score3...score12);
run;&lt;/PRE&gt;
&lt;P&gt;Note I use consistent case, the code window (its the {i} above post area) and indentation.&lt;/P&gt;
&lt;P&gt;For your questions:&lt;/P&gt;
&lt;P&gt;1) Note, this assumes the variable are in order, score1, score2 etc.&amp;nbsp; If not use and array and replace score1--score12 with of &amp;lt;arrayname&amp;gt;{*}.&lt;/P&gt;
&lt;PRE&gt;data want;
  set tbl1;
  num_miss=nmiss(score1--score12);
run;&lt;/PRE&gt;
&lt;P&gt;2) I don't get this question, the answer is always 12?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set tbl1;
  num_11=count(catx(',',score1--score12),"11");
run;&lt;/PRE&gt;
&lt;P&gt;4) Get this by using the index function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are all basic string manipulation functions which you can find in the SAS manual:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=titlepage.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Make a point of reading the manual.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 10:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464291#M118365</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-23T10:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464293#M118366</link>
      <description>&lt;P&gt;Quote:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"I created a vector of last 12 scores for each customer(with comma between values)."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are in command, I strongly (and I mean &lt;U&gt;&lt;STRONG&gt;STRONGLY&lt;/STRONG&gt;&lt;/U&gt;) recommend to use the correct data structure for this, creating a long dataset with 12 observations with a single variable. Then most of your calculations can be done by simple counts in SQL or data steps or with proc summary.&lt;/P&gt;
&lt;P&gt;If you add time-point variables to it, you gain by simply not writing a particular observation when the value is missing.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 07:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464293#M118366</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-23T07:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464308#M118369</link>
      <description>&lt;P&gt;Hi and thank you so much for your reply.&lt;/P&gt;&lt;P&gt;In my question 2&amp;nbsp;we need to get 12 for all rows because in all rows there are 12 arguments (numbers).&lt;/P&gt;&lt;P&gt;How can we calculate it please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 09:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464308#M118369</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-23T09:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464311#M118371</link>
      <description>&lt;PRE&gt;num_arg=12;&lt;/PRE&gt;
&lt;P&gt;Why would you want to calculate something that is fixed and known, just a waste of processing.&amp;nbsp; If you still want to use the countw() function which you can find in the docs.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 09:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464311#M118371</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-23T09:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464318#M118373</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;INDEX function returns the position of the first occurrence of the string’s first character.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need a different thing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to know in which position &amp;nbsp; (1 until 12) was first failure (value11)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 7 8 9 10 9 11 11 11 11 10 11 9 &amp;nbsp; &amp;nbsp;(Here the answer is 7)&lt;BR /&gt;2 8 8 7 7 7 7 6 7 7 8 7 11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 12)&lt;BR /&gt;3 3 3 3 3 2 2 2 3 3 3 2 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;BR /&gt;4 . . . . . . 0 0 0 0 6 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 10:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464318#M118373</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-05-23T10:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464319#M118374</link>
      <description>&lt;PRE&gt;data want;
  set tbl1;
  num_11=findw(catx(',',score1--score12),"11");
run;&lt;/PRE&gt;
&lt;P&gt;That should find first occurence of word.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 10:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464319#M118374</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-23T10:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464339#M118375</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If working with a wide table structure then I'd be using proper SAS array processing for this as shown below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1_wide tbl1_long;
  infile datalines dlm=' ' truncover;
  input ID Score1 Score2 Score3 Score4 Score5 Score6
    Score7 Score8 Score9 Score10 Score11 Score12;
  cards;
1 7 8 9 10 9 11 11 11 11 10 11 9
2 8 8 7 7 7 7 6 7 7 8 7 8
3 3 3 3 3 . 2 2 3 3 3 2 2
3 . . . . . 0 0 0 0 6 7
;
run;

data want;
  set tbl1_wide;
  array scores {*} Score1 - Score12;

  /*Question1-Calculate How many non-missing arguments exits in the vector.*/
  non_miss=n(of scores[*]);

  /*Question2-Calculate How many missing+non-missing arguments exits in the vector.*/
  miss_non_miss=dim(scores);

  do _i=1 to dim(scores);
    /*Question3-Calculate How many  times 11 appear*/
    n_11=sum(0 ,n_11 ,scores[_i]=11);

    /*Question4-Calculate location of first failure(11)*/
    if missing(pos_11) then
      do;
        if scores[_i]=11 then pos_11=_i;
      end;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 May 2018 11:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464339#M118375</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-23T11:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464398#M118396</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;INDEX function returns the position of the first occurrence of the string’s first character.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need a different thing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I need to know in which position &amp;nbsp; (1 until 12) was first failure (value11)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 7 8 9 10 9 11 11 11 11 10 11 9 &amp;nbsp; &amp;nbsp;(Here the answer is 7)&lt;BR /&gt;2 8 8 7 7 7 7 6 7 7 8 7 11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 12)&lt;BR /&gt;3 3 3 3 3 2 2 2 3 3 3 2 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;BR /&gt;4 . . . . . . 0 0 0 0 6 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Here the answer is 0)&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If these values are numeric and you will be numeric calculations later I strongly suggest looking at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s array approach.&lt;/P&gt;
&lt;P&gt;An alternate of&amp;nbsp;finding first value would be the WHICHN function (referencing Patricks array definition)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First11 = whichn(11, of scores(*));&lt;/P&gt;
&lt;P&gt;which does return 0 when the value in the first position is not found in any of the array elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 14:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculation-from-a-string/m-p/464398#M118396</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-23T14:39:18Z</dc:date>
    </item>
  </channel>
</rss>

