<?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: Help with arrays, index/find, if and do statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142760#M261709</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are just a couple of pieces of the puzzle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You've seen how INDEX locates the string anywhere within, not just at the beginning.&amp;nbsp; You've also used =: to examine the beginning of a string.&amp;nbsp; You can similarly use =: '72'.&amp;nbsp; And you can combine those using the IN operator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if diag{i} in: ('V270', '72', '73', '74') then prex=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It doesn't matter that the arguments are of different length ... in: figures it out properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For character ranges, you can use something along these lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if ('650' &amp;lt;= diag{i} &amp;lt; '670') then ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That might not get you all the way there, but it's a step or two further.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Jul 2014 18:56:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2014-07-30T18:56:26Z</dc:date>
    <item>
      <title>Help with arrays, index/find, if and do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142759#M261708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey all, I'm very new to SAS and have tried to find the answers to all this online but am still hitting roadblocks.&lt;/P&gt;&lt;P&gt;Here is the situation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I have a set of data where 15 of the variables are diagnoses (for a hospital) named dX1-dX15. &lt;/P&gt;&lt;P&gt;- for the 500 patients I'm working with, different codes have been assigned to them under these 15 variables&lt;/P&gt;&lt;P&gt;- I need to create a new variable "Prex" where every time one of the codes is present for a row, Prex=1 (and if not Prex=0)&lt;/P&gt;&lt;P&gt;- the codes I need are anything starting with 72, 73, 74 or with 650-669 or V27.. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; so the codes could be 72, 721, 7310, 74101, 658, 660445, V2791 etc.. (they all differ in length, but the key is that they start with any of&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; these options)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To this point, I have come up with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.nist1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set WORK.NIS_2002_10PCT_SAMPLE_A (obs=500);&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep key Prex dx1-dx15;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; Array Diagn (15) dx1-dx15;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to 15;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if Diagn(i)=:'V270' or index(Diagn(i),'72') or index(Diagn(i),'73') or index(Diagn(i),'74') &lt;/P&gt;&lt;P&gt;&amp;nbsp; then Prex=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;proc print data=work.nist1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id Prex;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problems I'm running into are:&lt;/P&gt;&lt;P&gt;- short of writing out an if statement for '650' '651' '652'... I have no idea how to index(or find) for the RANGE of codes starting with 650-669 (I thought maybe I could make a macro but that hasn't been working)&lt;/P&gt;&lt;P&gt;- I only need data that START with these numbers and yet data like '10973' are also showing up with Prex=1, so I'm unsure how to specify just the starting characters. &lt;/P&gt;&lt;P&gt;- I've tried the "find(Diagn(i),'72',startpos)" but was unsuccessful or maybe did it wrong. &lt;/P&gt;&lt;P&gt;- Also for character data you're supposed to be able to write " Where var Like 'N%' " and have it give you everything starting with N, regardless of what comes after. I figured out that for an IF statement, I can do "If var=:" as an equivalent to the like statement but it doesn't work to do &lt;/P&gt;&lt;P&gt;" If Diagn(i)=:'V27%' " - is there another symbol to use or what would be the best way to specify that the code #'s are at the start?&lt;/P&gt;&lt;P&gt;- Also originally I had an "Else Prex=0" statement before the End statement, but that was turning all of Prex into 0's (not sure why)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully this has made some sense and I'm really hoping that I'm not too far off from a solution.&lt;/P&gt;&lt;P&gt;Any help is massively appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 18:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142759#M261708</guid>
      <dc:creator>nick1990</dc:creator>
      <dc:date>2014-07-30T18:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays, index/find, if and do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142760#M261709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are just a couple of pieces of the puzzle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You've seen how INDEX locates the string anywhere within, not just at the beginning.&amp;nbsp; You've also used =: to examine the beginning of a string.&amp;nbsp; You can similarly use =: '72'.&amp;nbsp; And you can combine those using the IN operator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if diag{i} in: ('V270', '72', '73', '74') then prex=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It doesn't matter that the arguments are of different length ... in: figures it out properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For character ranges, you can use something along these lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if ('650' &amp;lt;= diag{i} &amp;lt; '670') then ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That might not get you all the way there, but it's a step or two further.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 18:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142760#M261709</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-07-30T18:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays, index/find, if and do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142761#M261710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a ton!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 19:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142761#M261710</guid>
      <dc:creator>nick1990</dc:creator>
      <dc:date>2014-07-30T19:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays, index/find, if and do statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142762#M261711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following code may get you started:&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; code $;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;72&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;721&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;00721&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;653&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;667&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;vb665&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;V27adfjl&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;adfsjV27&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; var $ &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;5000&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; i=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;650&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;to&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;669&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=catx(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'|'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;, var,i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var=catx(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'|'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,var,&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;72&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;73&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;74&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'V27'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; symputx(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'var'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,var);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prex = prxmatch(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;"/^(&amp;amp;var)/"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;, code)&amp;gt;&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 20:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays-index-find-if-and-do-statements/m-p/142762#M261711</guid>
      <dc:creator>haikuobian</dc:creator>
      <dc:date>2014-07-30T20:38:28Z</dc:date>
    </item>
  </channel>
</rss>

