<?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 do I use array and substr function? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501685#M133804</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I want only one variable created from this called XX. But I want to use the "substr" function too? Yours doesnt incluse that function.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You said "first five position of 5 diagnoses are "250.1"&amp;nbsp;" which is why I propose use of the =: If you use substr&amp;nbsp; requesting 5 positions and the value does not contain 5 positions you have problems. See this code and the error it generates.&lt;/P&gt;
&lt;PRE&gt;data example;
   x='933';
   y = substr(x,1,5);
run;&lt;/PRE&gt;
&lt;P&gt;By&amp;nbsp; the time you add in additional code involving handling shorter variables the code is 1) less efficient and 2) just plain longer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no reason to use a function why force a solution using it. That way lies bureaucratic madness.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 20:50:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-10-04T20:50:08Z</dc:date>
    <item>
      <title>How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501667#M133795</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data ss;
   infile datalines;
   input Patient_Number Encounter_Number Birth_Date Diagnosis_1$ Diagnosis_2$ Diagnosis_3$ Diagnosis_4$ Diagnosis_5$;
 datalines;
   
    1 1 31JUL1975 250.7 250.7 785.2
    1 2 31JUL1975 250.3 250.3 288.8 995.93 466 250.1
    1 3 31JUL1975 250.3 250.3 271.6                   288.8
    1 4 31JUL1975 250.3 250.3            250.1
    1 5 31JUL1975 250.1 250.1
   

  &lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Array diag {5} $1 diagnosis_1-diagnosis_5;
	keto=0;
	do i=1 to 5;
			if substr(diag[i],1,5) in ('250.1') then keto=1;
	end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If the first five position of 5 diagnoses are "250.1" then it indicates "XX". Using "ARRAY" and function "SUBSTR", how do i generate a new "XX" indicator variable?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 19:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501667#M133795</guid>
      <dc:creator>JUMMY</dc:creator>
      <dc:date>2018-10-04T19:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501670#M133797</link>
      <description>&lt;P&gt;It will really help to provide an example of what the desired result should be.&lt;/P&gt;
&lt;P&gt;For instance what if multiple variables meet the condition? Do you want multiple results for "keto"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want to know "at least one of the variables has a value with 250.1" then this may work:&lt;/P&gt;
&lt;PRE&gt;data ss;
   infile datalines truncover;
   input Patient_Number Encounter_Number Birth_Date :date9. Diagnosis_1$ Diagnosis_2$ Diagnosis_3$ Diagnosis_4$ Diagnosis_5$;
   format birth_date date9.;
   keto = index(catx('_',of diag:),'250.1')&amp;gt;0;

 datalines;
1 1 31JUL1975 250.7 250.7 785.2
1 2 31JUL1975 250.3 250.3 288.8 995.93 466 250.1
1 3 31JUL1975 250.3 250.3 271.6   .      .   .       288.8
1 4 31JUL1975 250.3 250.3   .     .    250.1
1 5 31JUL1975 250.1 250.1
;
run;&lt;/PRE&gt;
&lt;P&gt;If you have values such as 1250.1 that would also indicate keto, so may not be appropriate. We don't know all your possible values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;PRE&gt;data ss;
   infile datalines truncover;
   input Patient_Number Encounter_Number Birth_Date :date9. Diagnosis_1$ Diagnosis_2$ Diagnosis_3$ Diagnosis_4$ Diagnosis_5$;
   format birth_date date9.;
   array d diagnosis:;
   keto=0;
   do i= 1 to dim(d);
      if d[i] =: '250.1' then do;
         keto=1;
         leave;
      end;
   end;

 datalines;
1 1 31JUL1975 250.7 250.7 785.2
1 2 31JUL1975 250.3 250.3 288.8 995.93 466 250.1
1 3 31JUL1975 250.3 250.3 271.6   .      .   .       288.8
1 4 31JUL1975 250.3 250.3   .     .    250.1
1 5 31JUL1975 250.1 250.1
;
run;&lt;/PRE&gt;
&lt;P&gt;The =: is a "begins with" comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Leave says to stop the loop as soon as the condition is found to be true.&lt;/P&gt;
&lt;P&gt;You might want to leave the I variable in the set as it would have the indicator for which of the diagnosis variables met the condition.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 19:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501670#M133797</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-04T19:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501675#M133799</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I want only one variable created from this called XX. But I want to use the "substr" function too? Yours doesnt incluse that function.</description>
      <pubDate>Thu, 04 Oct 2018 19:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501675#M133799</guid>
      <dc:creator>JUMMY</dc:creator>
      <dc:date>2018-10-04T19:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501680#M133801</link>
      <description>&lt;P&gt;I don't understand the question. You already posted the code for when XX is KETO.&amp;nbsp; What do you want to do differently?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 19:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501680#M133801</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-04T19:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501682#M133803</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ss;
   infile datalines missover;
   input Patient_Number Encounter_Number Birth_Date :date9. @;
   array DIAG[6] $5;
   input diag[*];
   keto = '250.1' in diag;
   format Bir: date9.;
   datalines;
 1 1 31JUL1975 250.7 250.7 785.2
 1 2 31JUL1975 250.3 250.3 288.8 995.93 466 250.1
 1 3 31JUL1975 250.3 250.3 271.6    .    .   288.8
 1 4 31JUL1975 250.3 250.3    .  250.1
 1 5 31JUL1975 250.1 250.1
;;;;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 20:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501682#M133803</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-10-04T20:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501685#M133804</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226541"&gt;@JUMMY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I want only one variable created from this called XX. But I want to use the "substr" function too? Yours doesnt incluse that function.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You said "first five position of 5 diagnoses are "250.1"&amp;nbsp;" which is why I propose use of the =: If you use substr&amp;nbsp; requesting 5 positions and the value does not contain 5 positions you have problems. See this code and the error it generates.&lt;/P&gt;
&lt;PRE&gt;data example;
   x='933';
   y = substr(x,1,5);
run;&lt;/PRE&gt;
&lt;P&gt;By&amp;nbsp; the time you add in additional code involving handling shorter variables the code is 1) less efficient and 2) just plain longer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no reason to use a function why force a solution using it. That way lies bureaucratic madness.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 20:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501685#M133804</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-04T20:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501696#M133805</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substrn(x,1,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or SUBPAD depending on the result needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I see no use for SUBSTR or to iterate over the array.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 21:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501696#M133805</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-10-04T21:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use array and substr function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501716#M133812</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no reason to use a function why force a solution using it. That way lies bureaucratic madness.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's homework.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 01:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-array-and-substr-function/m-p/501716#M133812</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-05T01:49:56Z</dc:date>
    </item>
  </channel>
</rss>

