<?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: Using array to create a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743236#M232650</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272059"&gt;@sandrube&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a DO-UNTIL loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data */

data have;
input ID DXCCS1-DXCCS5 Result;
datalines;
1 67 73 43 1 34 43
2 2 87 67 62 92 .
3 9 32 . 5 2 32
4 34 6 90 93 88 34
5 5 53 84 68 4 .
6 55 76 67 56 29 29
7 12 82 . . 11 12
8 10 49 76 67 99 .
9 78 24 56 93 11 24
10 3 1 2 82 99 .
;

/* Find first array value in ]11, 45[ */

data want(drop=h);
set have;
array DXCCS[*] DXCCS:;
do h=1 to dim(DXCCS) until(11&amp;lt;DXCCS(h)&amp;lt;45);
end;
if h&amp;lt;=dim(DXCCS) then nccs=DXCCS(h);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I've corrected your missing &lt;FONT face="courier new,courier"&gt;Result&lt;/FONT&gt; for ID 6 and the typo in "&lt;SPAN&gt;DCCS1".&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 23 May 2021 15:36:12 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-05-23T15:36:12Z</dc:date>
    <item>
      <title>Using array to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743227#M232642</link>
      <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;I have the following data set. I'm trying to create a variable 'nccs', which is first number between 11-45 among the variables DXCCS1-DXCCS5. That way, 'nccs' would be similar to variable 'Result'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data;&lt;BR /&gt;input ID DCCS1 DXCCS2 DXCCS3 DXCCS4 DXCCS5 Result;&lt;BR /&gt;datalines;&lt;BR /&gt;1 67 73 43 1 34 43&lt;BR /&gt;2 2 87 67 62 92 .&lt;BR /&gt;3 9 32 . 5 2 32&lt;BR /&gt;4 34 6 90 93 88 34&lt;BR /&gt;5 5 53 84 68 4 .&lt;BR /&gt;6 55 76 67 56 29 .&lt;BR /&gt;7 12 82 . . 11 12&lt;BR /&gt;8 10 49 76 67 99 .&lt;BR /&gt;9 78 24 56 93 11 24&lt;BR /&gt;10 3 1 2 82 99 .&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data_1;&lt;BR /&gt;set data;&lt;BR /&gt;array DXCCS DXCCS1-DXCCS5;&lt;BR /&gt;do h=1 to dim(DXCCS);&lt;BR /&gt;if DXCCS(h) ne . then do;&lt;BR /&gt;if nccs_CCS = . and (DXCCS(h)&amp;gt;11 and DXCCS(h)&amp;lt;45) then nccs = DXCCS(h);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you and have a wonderful weekend!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rube&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 14:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743227#M232642</guid>
      <dc:creator>sandrube</dc:creator>
      <dc:date>2021-05-23T14:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using array to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743234#M232648</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 88         data data_1;
 89         set data;
 90         array DXCCS DXCCS1-DXCCS5;
 91         do h=1 to dim(DXCCS);
 92         if DXCCS(h) ne . then do;
 93         if nccs_CCS = . and (DXCCS(h)&amp;gt;11 and DXCCS(h)&amp;lt;45) then nccs = DXCCS(h);
 94         end;
 95         end;
 96         run;
 
 NOTE: Variable nccs_CCS is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;The NOTE tells you that you try to use a variable that&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;does not exist in the incoming dataset&lt;/LI&gt;
&lt;LI&gt;is never set to a value in the step&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I guess that nccs_CCS is a typo and you wanted to use nccs.&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 15:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743234#M232648</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-23T15:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using array to create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743236#M232650</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272059"&gt;@sandrube&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a DO-UNTIL loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data */

data have;
input ID DXCCS1-DXCCS5 Result;
datalines;
1 67 73 43 1 34 43
2 2 87 67 62 92 .
3 9 32 . 5 2 32
4 34 6 90 93 88 34
5 5 53 84 68 4 .
6 55 76 67 56 29 29
7 12 82 . . 11 12
8 10 49 76 67 99 .
9 78 24 56 93 11 24
10 3 1 2 82 99 .
;

/* Find first array value in ]11, 45[ */

data want(drop=h);
set have;
array DXCCS[*] DXCCS:;
do h=1 to dim(DXCCS) until(11&amp;lt;DXCCS(h)&amp;lt;45);
end;
if h&amp;lt;=dim(DXCCS) then nccs=DXCCS(h);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I've corrected your missing &lt;FONT face="courier new,courier"&gt;Result&lt;/FONT&gt; for ID 6 and the typo in "&lt;SPAN&gt;DCCS1".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 May 2021 15:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-array-to-create-a-new-variable/m-p/743236#M232650</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-23T15:36:12Z</dc:date>
    </item>
  </channel>
</rss>

