<?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: Data preparation for a line chart and using array index in different range in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425067#M68256</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your inputs!! I truly appreciate it.&amp;nbsp;I&amp;nbsp;now got&amp;nbsp;the logic behind your do loop and I'd like to use this approach for final data preparation for a chart.&amp;nbsp;May I have a question please?&lt;/P&gt;&lt;P&gt;The resulting data 'want' is correct except row 11 and 13&amp;nbsp;has wrong&amp;nbsp;values for a variable 'category'.&amp;nbsp;What went wrong&amp;nbsp;in modifying your do loop? I will summarize data for a chart after 'category' variable is created. Thanks zillions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever denom obs years;
datalines;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2002
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2003
2 1 1 1 1 1 1 1 1 1 1 1 0 1 3 0 2002
3 1 1 1 1 1 1 1 1 0 0 0 0 1 4 1 2003
4 1 1 1 1 1 0 0 0 0 0 0 0 1 5 1 2004
5 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2004
6 1 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2004
;

data want;
    SET have;
    length category $13;
     if min(of bf1--bf12)=1 and max(of bf1--bf12)=1 then 
        category='BF 12M+ (Yes)';
    else 
    do;
        if min(of bf1--bf12)=0 and max(of bf1--bf12)=0 then 
            category='BF 12M+ (No)';
        else
        do;
            if min(of bf1--bf11)=1 and max(of bf1--bf11)=1 then 
                category='BF 12M (Yes)';
            else 
            do;
                if min(of bf1--bf11)=0 and max(of bf1--bf11)=0 then 
                    category='BF 12M (No)';
                else
                do;
                    if min(of bf1--bf8)=1 and max(of bf1--bf8)=1 then 
                        category='BF 9M (Yes)';
                    else 
                    do;
                        if min(of bf1--bf8)=0 and max(of bf1--bf8)=0 then 
                            category='BF 9M (No)';
	else
        do;
            if min(of bf1--bf5)=1 and max(of bf1--bf5)=1 then 
                category='BF 6M (Yes)';
            else 
            do;
                if min(of bf1--bf5)=0 and max(of bf1--bf5)=0 then 
                    category='BF 6M (No)';
	else
        do;
            if min(of bf1--bf2)=1 and max(of bf1--bf2)=1 then 
                category='BF 3M (Yes)';
            else 
            	do;
                if min(of bf1--bf2)=0 and max(of bf1--bf2)=0 then 
                    category='BF 3M (No)';
				else 
					do;
					if min(of bf1--bf12)=0 and max(of bf1--bf12)=0 and ever=1 then 
                            category='BF 1Mo (Yes)';
                         else category='BF 1Mo (No)';
                    end; 
                end;
            end; 
        end;
    end; 
end; 
end; 
end;
end;
end;

    output;
    if (ever=1) then 
        category='BF Ever (Yes)';
     else
        category='BF Ever (No)';
    output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2018 22:04:56 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-01-04T22:04:56Z</dc:date>
    <item>
      <title>Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424609#M68202</link>
      <description>&lt;P&gt;I'd like to reproduce image below showing how&amp;nbsp;soil fertility relate to&amp;nbsp;BF categories based on&amp;nbsp;fertilization&amp;nbsp;durations over&amp;nbsp;time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chart.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17614i9FF5F1ACFAEA17EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="chart.png" alt="chart.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have is the sample of my data. I'm totally confused!!! I&amp;nbsp;feel like an idiot anyway.&amp;nbsp;Try not to&amp;nbsp;judge me please. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question1: First off, I thought creating categorical variable 'bfcat'&amp;nbsp;shown in my array code below would help&amp;nbsp;create categorical variable for&amp;nbsp;'BF categories based on&amp;nbsp;fertilization&amp;nbsp;durations' that splits lines in the image above. Please see&amp;nbsp;Chart legend, e.g., BF ever(yes,no) et.c.&amp;nbsp;&amp;nbsp;But creating variable 'bfcat'&amp;nbsp;doesn't make sense, right?&amp;nbsp;Any alternative suggestions as to how I should organize my data to come up with similar chart shown above please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question2: &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Array code gave error:&lt;/P&gt;&lt;P&gt;ERROR: Array subscript out of range at line 223 column 4.&lt;/P&gt;&lt;P&gt;What am I doing wrong here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever; 
datalines;
1	1	1	1	1	1	1	1	1	1	1	1	1	1
2	1	1	1	1	0	0	0	0	0	0	0	0	1
3	1	1	0	0	0	0	0	0	0	0	0	0	1
4	1	0	0	0	0	0	0	0	0	0	0	0	1
5	0	0	0	0	0	0	0	0	0	0	0	0	0
6	1	1	1	1	1	1	1	0	0	0	0	0	1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data test; set have;
array x (12) BF_1-BF_12;
do i=1 to 12;
if x(1-12)=1 then bfcat=121; else bfcat=120;
if x(1-6)=1 then bfcat=61; else bfcat=60;
if x(1-3)=1 then bfcat=31; else bfcat=30;
if x(1)=1 then bfcat=11; else bfcat=10;
end;
if bf_ever=1 then bfcat=1; else bfcat=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 16:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424609#M68202</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-03T16:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424613#M68203</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, lets just look at your array step for the moment and fix that.&amp;nbsp; You don't do ranges as such like that, do you mean if all of elements 1-12 are 1 then bfcat=121 then something like:&lt;/P&gt;
&lt;PRE&gt;data have; 
  input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever; 
datalines;
1   1   1   1   1   1   1   1   1   1   1   1   1   1
2   1   1   1   1   0   0   0   0   0   0   0   0   1
3   1   1   0   0   0   0   0   0   0   0   0   0   1
4   1   0   0   0   0   0   0   0   0   0   0   0   1
5   0   0   0   0   0   0   0   0   0   0   0   0   0
6   1   1   1   1   1   1   1   0   0   0   0   0   1
;
run;

data test; 
  set have;
  if min(of bf1--bf12)=1 and max(of bf1--bf12)=1 then bfcat=121;
  else if min(of bf1--bf6)=1 and max(of bf1--bf6)=1 then bfcat=61;
  else if ever=1 then bfcat=1;
run;&lt;/PRE&gt;
&lt;P&gt;However you will need to explain your logic further as you have else statements of your if's as well.&amp;nbsp; This:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; x&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; bfcat&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;121&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; bfcat&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;120&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Means that bfcat will either be 121 or 120 - but this will be overwritten by the next if, and the last if with the ever will always overide everything else.&amp;nbsp; Thats why I made it else's in the given code.&amp;nbsp; Also note you don't need the array or loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 16:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424613#M68203</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-03T16:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424616#M68204</link>
      <description>&lt;P&gt;Transpose your data to a wide format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should look like, with Year, where's year in your data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Year Category Value&lt;/P&gt;
&lt;P&gt;1 2013 BF1 1&lt;/P&gt;
&lt;P&gt;1 2013 BF2 1&lt;/P&gt;
&lt;P&gt;1 2013 BF3 1&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;1 2014 BF1 1&lt;/P&gt;
&lt;P&gt;1 2014 BF2 1&lt;/P&gt;
&lt;P&gt;2 2013 BF1 1&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then your code will be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=have;
series x=year y=value / group=category;
run;&lt;/CODE&gt;&lt;/PRE&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/132289"&gt;@Cruise&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I'd like to reproduce image below showing how&amp;nbsp;soil fertility relate to&amp;nbsp;BF categories based on&amp;nbsp;fertilization&amp;nbsp;durations over&amp;nbsp;time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chart.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17614i9FF5F1ACFAEA17EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="chart.png" alt="chart.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have is the sample of my data. I'm totally confused!!! I&amp;nbsp;feel like an idiot anyway.&amp;nbsp;Try not to&amp;nbsp;judge me please. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question1: First off, I thought creating categorical variable 'bfcat'&amp;nbsp;shown in my array code below would help&amp;nbsp;create categorical variable for&amp;nbsp;'BF categories based on&amp;nbsp;fertilization&amp;nbsp;durations' that splits lines in the image above. Please see&amp;nbsp;Chart legend, e.g., BF ever(yes,no) et.c.&amp;nbsp;&amp;nbsp;But creating variable 'bfcat'&amp;nbsp;doesn't make sense, right?&amp;nbsp;Any alternative suggestions as to how I should organize my data to come up with similar chart shown above please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question2: &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array code gave error:&lt;/P&gt;
&lt;P&gt;ERROR: Array subscript out of range at line 223 column 4.&lt;/P&gt;
&lt;P&gt;What am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever; 
datalines;
1	1	1	1	1	1	1	1	1	1	1	1	1	1
2	1	1	1	1	0	0	0	0	0	0	0	0	1
3	1	1	0	0	0	0	0	0	0	0	0	0	1
4	1	0	0	0	0	0	0	0	0	0	0	0	1
5	0	0	0	0	0	0	0	0	0	0	0	0	0
6	1	1	1	1	1	1	1	0	0	0	0	0	1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data test; set have;
array x (12) BF_1-BF_12;
do i=1 to 12;
if x(1-12)=1 then bfcat=121; else bfcat=120;
if x(1-6)=1 then bfcat=61; else bfcat=60;
if x(1-3)=1 then bfcat=31; else bfcat=30;
if x(1)=1 then bfcat=11; else bfcat=10;
end;
if bf_ever=1 then bfcat=1; else bfcat=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 16:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424616#M68204</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-03T16:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424622#M68205</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; had mentioned, your data should be converted to have three columns (year, Category, value) and 48 rows (2003 - 2013 by 2 yrs increments)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This how I generated my Sample data to "reproduce" your chart&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(KEEP=year cat val);
    length year 4 cat $12 val 4; 
    array bfs {8} $12 bf1 - bf8 ('BF Ever (Yes)' 'BF Ever (No)' 'BF 4WK+ (Yes)' 'BF 4WK+ (No)' 'BF 3M+ (Yes)' 'BF 3M+ (No)' 'BF 12M+ (Yes)' 'BF 12M+ (No)');
    do year=2003 to 2013 by 2;
        do i=1 to dim(bfs);
            cat = bfs[i];
            val = rand('uniform') * 10; /* Used Random numbers */
            output;
        end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For Custom line styling and coloring, you could use SAS/GRAPH SYMBOL, LEGEND, and AXIS statements prior to Proc Gplot, or use other SAS charting procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I used the Line Plot Wizard in SAS Enterprise Guide, to generate my chart.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 17:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424622#M68205</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2018-01-03T17:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424657#M68213</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&lt;/P&gt;&lt;P&gt;I have about 5 million rows. Does transpose work for large dataset like this? SAS crashed with below code. I still don't understand the benefit of transposing, can you please explain a little more?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=realdata;
out=temp
name=transposed_col;
VAR BF_1-BF_12;
by id survey_yr;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424657#M68213</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-03T18:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424659#M68214</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Chart shows data by BF12M+(Yes) vs BF12M+(No), BF3M+(Yes) vs BF3M+(No),&amp;nbsp;BF1M+(Yes) vs BF1M+(No),&amp;nbsp;BF ever(Yes) vs BF ever+(No). That's where my confusion came from with "if-else-then" logic. I like your strategy, but I'm wondering how I would come up with data produced&amp;nbsp;from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&amp;nbsp;'s sample data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 18:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424659#M68214</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-03T18:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424672#M68217</link>
      <description>&lt;P&gt;Transposing would mean that you can use the GROUP option in my sample SGPLOT. If you don't then you need to have a series statement for each line, which can be cumbersome.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5 million rows * 10 variables would be a 50 million row data set. I'm assuming that at some point you actually summarize the data to graph it...showing 5 million data points on any graph would be problematic.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 19:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424672#M68217</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-03T19:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424732#M68238</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question2: &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array code gave error:&lt;/P&gt;
&lt;P&gt;ERROR: Array subscript out of range at line 223 column 4.&lt;/P&gt;
&lt;P&gt;What am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever; 
datalines;
1	1	1	1	1	1	1	1	1	1	1	1	1	1
2	1	1	1	1	0	0	0	0	0	0	0	0	1
3	1	1	0	0	0	0	0	0	0	0	0	0	1
4	1	0	0	0	0	0	0	0	0	0	0	0	1
5	0	0	0	0	0	0	0	0	0	0	0	0	0
6	1	1	1	1	1	1	1	0	0	0	0	0	1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;data test; set have;
array x (12) BF_1-BF_12;
do i=1 to 12;
if x(1-12)=1 then bfcat=121; else bfcat=120;
if x(1-6)=1 then bfcat=61; else bfcat=60;
if x(1-3)=1 then bfcat=31; else bfcat=30;
if x(1)=1 then bfcat=11; else bfcat=10;
end;
if bf_ever=1 then bfcat=1; else bfcat=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The array subscript&amp;nbsp;out of bound comes from each of the statements like this:&lt;/P&gt;
&lt;P&gt;if x(1-12)=1 then bfcat=121;&lt;/P&gt;
&lt;P&gt;The values inside the parentheses are used in a calculation to find the&amp;nbsp;subscript of the array. Since 1-12 = -11 that is invalid for an&amp;nbsp;array the way you defined x. Similarly 1-6 and 1-3 generate negative values and invalid subscripts of -5 and -2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The calculation in the array subscript is common as often we do an offset such as x(i+1) to reference an element of the array but would need to make sure that the calculation resolves to something inside the defined subscripts for an array.&lt;/P&gt;
&lt;P&gt;Here is a brief example of an array that allows negative subscripts:&lt;/P&gt;
&lt;PRE&gt;data example;
   array x (-10:-5) ;
   do i= -10 to -5;
      x(i)= i;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice the names of the variables created by the array. Arrays defined with a lower: upper bound are useful for things that have known integer behavior but don't conveniently start at 1 such as year values.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 20:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424732#M68238</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-03T20:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424759#M68240</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;,&lt;BR /&gt;To provide you with way to re-produce my sample data Structure, please answer these two questions:&lt;BR /&gt;Q1: What does your 5 Million records data set look like, in terms of structure?&lt;BR /&gt;&lt;BR /&gt;Q2: What does your categories, such as "BF 12M+ (Yes)" mean? Are these calculation with 1==Yes, 0==No? while 12M+ means 12 months or More? Are your bf1 -- bf12 represent months?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ahmed</description>
      <pubDate>Wed, 03 Jan 2018 21:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424759#M68240</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2018-01-03T21:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424810#M68242</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Q1: Please see attached image below. I'm awfully sorry for providing you with a screenshot for an idea of how my real data looks like. My SAS on laptop had expired.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ahmed.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17640iE494BE0557420388/image-size/large?v=v2&amp;amp;px=999" role="button" title="ahmed.png" alt="ahmed.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Q2: What does your categories, such as "BF 12M+ (Yes)" mean?&lt;BR /&gt;- "BF 12M+ (Yes)" means that given individual had received BF treatment for longer than 12 months vs "BF 12M+ (No)"&amp;nbsp; means "else, then less than 12 months".&lt;BR /&gt;- Yes, 1==Yes, 0==No.&lt;BR /&gt;- While 12M+ means 12 months or More? Yes, you're right.&lt;BR /&gt;- Are your bf1 -- bf12 represent months? Yes, they're number of months that treatment BF continued.&lt;BR /&gt;- As shown in the data screen shot, id=1 invidual volunteered for measurements at his/her age of 1,2,3 and 4 and known to have BF treatment for more than 12 months. Thus also takes value 1 for "ever" variable.&lt;BR /&gt;Individual id=2 volunteered for only one measurement at age category of 1 and known to have BF treatment for only 2 months.&amp;nbsp; Individual id=3 had never received a BF treatment thus took "0" for "ever" variable and 0 for across all BF dummy variables. Same logic applies for id=4 who has 3 measurements but treatment continued for only 1 month.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much Ahmed!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 02:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424810#M68242</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-04T02:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424951#M68249</link>
      <description>&lt;P&gt;You should really type it out or provide data in a text format, otherwise to work with it, we have to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like you're skipping a whole bunch of steps and logic here in what needs to happen. Please take some time to detail your data structure. It sounds like your BF groups/lines you want to draw are not pre-calculated, so that's likely the step you should start with. You can worry about format for a chart when you reach that point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424951#M68249</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-04T15:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424952#M68250</link>
      <description>&lt;P&gt;Hi Cruise,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your sample data, here is what I was to come up with,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (Keep=id year category values);

    SET work.have(rename=(measurment_years=year));
    length category $13;

     if min(of bf1--bf12)=1 and max(of bf1--bf12)=1 then 
        category='BF 12M+ (Yes)';
    else 
    do;
        if min(of bf1--bf12)=0 and max(of bf1--bf12)=0 then 
            category='BF 12M+ (No)';
        else
        do;
            if min(of bf1--bf6)=1 and max(of bf1--bf6)=1 then 
                category='BF 6M+ (Yes)';
            else 
            do;
                if min(of bf1--bf6)=0 and max(of bf1--bf6)=0 then 
                    category='BF 6M+ (No)';
                else
                do;
                    if min(of bf1--bf3)=1 and max(of bf1--bf3)=1 then 
                        category='BF 3M+ (Yes)';
                    else 
                    do;
                        if min(of bf1--bf3)=0 and max(of bf1--bf3)=0 then 
                            category='BF 3M+ (No)';
                        else if (bf1=1) then 
                            category='BF 4WK+ (Yes)';
                         else
                            category='BF 4WK+ (No)';
                    end; /* End of 3M+ check */
                end;
            end; /* End of 6M+ check */
        end;
    end; /* End of 12M+ check */
    output;
    if (ever=1) then 
        category='BF Ever (Yes)';
     else
        category='BF Ever (No)';
    output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, I used the evaluation logic suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;, and I assumed your categories are mutually exclusive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: I just added an excel version of your data image as an attachment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 16:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/424952#M68250</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2018-01-04T16:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425004#M68252</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&lt;/P&gt;&lt;P&gt;This is good ! The guy who created the data is not here anymore. However, I have just learned that variable 'category' is inclusive which is meaning:&lt;/P&gt;&lt;P&gt;BF_1: individual received treatment for more than one month. BF_3 means that individual received treatment for more than 3 months instead equal to 3 months., so forth so on.&amp;nbsp;So below simple array is correct even though I still need complementary categories of (No) for each category created exactly by&amp;nbsp;the manner you demonstrated in your last do loop.&amp;nbsp;Please note that the logic&amp;nbsp;underlying&amp;nbsp;"if EVER=1 and x(i)=0 then bf='BF 3M (Yes)'; "&amp;nbsp;is true given internal data&amp;nbsp;log note.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now question becomes:&lt;/P&gt;&lt;P&gt;If I modify your code to ...min(of bf3--bf5) instead min(of bf1--bf5)&amp;nbsp;do we still need&amp;nbsp;'else' logic&amp;nbsp;there?&amp;nbsp;Sorry, if it's only confusing.&lt;/P&gt;&lt;P&gt;Would you mind to&amp;nbsp;show me&amp;nbsp;how your do loop would be modified&amp;nbsp;given&amp;nbsp;'category'&amp;nbsp;was inclusive as I described above?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array x (12) BF_1-BF_12;
do i=1 to 12;
if EVER=1 and x(i)=0 then cat='BF 3M (Yes)'; 
end;
if EVER =0 then cat='BF Ever (No)'; 
if BF_1=1 or BF_2=1 then cat='BF 3M (Yes)';  
if BF_3=1 or BF_4=1 or BF_5=1 then cat='BF 6M (Yes)';  
if BF_6=1 or BF_7=1 or BF_8=1 then cat='BF 9M (Yes)'; 
if BF_9=1 or BF_10=1 or BF_11=1 then cat='BF 12M (Yes)'; 
if BF_12=1 then cat='BF 12M+ (Yes)';

where 'cat' in above code means: 
BF Ever (No) vs (Yes)=never vs ever received treatment 
BF 3M (Yes)=received BF treatment for 3 months 
BF 6M (Yes)=received BF treatment for 6 months 
BF 9M (Yes)=received BF treatment for 9 months 
BF 12M (Yes)=received BF treatment for 12 months 
BF 12M+ (Yes)=received BF treatment beyond 12 months 
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425004#M68252</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-04T17:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425055#M68255</link>
      <description>Hi,&lt;BR /&gt;I'm sorry, but I'm a little bit confused by your reply, and I don't fully understand your requirements!&lt;BR /&gt;It seems you have changed the logic around from your original questions and how to reproduce the line plot/chart.&lt;BR /&gt;&lt;BR /&gt;You have been provided with various coding techniques and approaches already, and now it's your turn to experiment and learn more about how to customize them to meet your requirements.&lt;BR /&gt;&lt;BR /&gt;If you want to get SAS on your laptop again, try to download SAS University Edition (&lt;A href="https://www.sas.com/en_us/software/university-edition/download-software.html" target="_blank"&gt;https://www.sas.com/en_us/software/university-edition/download-software.html&lt;/A&gt;).&lt;BR /&gt;&lt;BR /&gt;Ahmed</description>
      <pubDate>Thu, 04 Jan 2018 20:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425055#M68255</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2018-01-04T20:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425067#M68256</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13868"&gt;@AhmedAl_Attar&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your inputs!! I truly appreciate it.&amp;nbsp;I&amp;nbsp;now got&amp;nbsp;the logic behind your do loop and I'd like to use this approach for final data preparation for a chart.&amp;nbsp;May I have a question please?&lt;/P&gt;&lt;P&gt;The resulting data 'want' is correct except row 11 and 13&amp;nbsp;has wrong&amp;nbsp;values for a variable 'category'.&amp;nbsp;What went wrong&amp;nbsp;in modifying your do loop? I will summarize data for a chart after 'category' variable is created. Thanks zillions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id bf1 bf2 bf3 bf4 bf5 bf6 bf7 bf8 bf9 bf10 bf11 bf12 ever denom obs years;
datalines;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2002
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2003
2 1 1 1 1 1 1 1 1 1 1 1 0 1 3 0 2002
3 1 1 1 1 1 1 1 1 0 0 0 0 1 4 1 2003
4 1 1 1 1 1 0 0 0 0 0 0 0 1 5 1 2004
5 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2004
6 1 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2004
;

data want;
    SET have;
    length category $13;
     if min(of bf1--bf12)=1 and max(of bf1--bf12)=1 then 
        category='BF 12M+ (Yes)';
    else 
    do;
        if min(of bf1--bf12)=0 and max(of bf1--bf12)=0 then 
            category='BF 12M+ (No)';
        else
        do;
            if min(of bf1--bf11)=1 and max(of bf1--bf11)=1 then 
                category='BF 12M (Yes)';
            else 
            do;
                if min(of bf1--bf11)=0 and max(of bf1--bf11)=0 then 
                    category='BF 12M (No)';
                else
                do;
                    if min(of bf1--bf8)=1 and max(of bf1--bf8)=1 then 
                        category='BF 9M (Yes)';
                    else 
                    do;
                        if min(of bf1--bf8)=0 and max(of bf1--bf8)=0 then 
                            category='BF 9M (No)';
	else
        do;
            if min(of bf1--bf5)=1 and max(of bf1--bf5)=1 then 
                category='BF 6M (Yes)';
            else 
            do;
                if min(of bf1--bf5)=0 and max(of bf1--bf5)=0 then 
                    category='BF 6M (No)';
	else
        do;
            if min(of bf1--bf2)=1 and max(of bf1--bf2)=1 then 
                category='BF 3M (Yes)';
            else 
            	do;
                if min(of bf1--bf2)=0 and max(of bf1--bf2)=0 then 
                    category='BF 3M (No)';
				else 
					do;
					if min(of bf1--bf12)=0 and max(of bf1--bf12)=0 and ever=1 then 
                            category='BF 1Mo (Yes)';
                         else category='BF 1Mo (No)';
                    end; 
                end;
            end; 
        end;
    end; 
end; 
end; 
end;
end;
end;

    output;
    if (ever=1) then 
        category='BF Ever (Yes)';
     else
        category='BF Ever (No)';
    output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 22:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425067#M68256</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-01-04T22:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Data preparation for a line chart and using array index in different range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425217#M68257</link>
      <description>&lt;P&gt;Hi Cruise,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What were you expecting the category value for row 11 &amp;amp; 13 in your output (Want) data set?&lt;/P&gt;
&lt;P&gt;From looking at the input rows and your conditions (ever=1)&lt;/P&gt;
&lt;P&gt;5 0 0 0 0 0 0 0 0 0 0 0 0&lt;FONT color="#FF0000"&gt; 0&lt;/FONT&gt; 6 1 2004&amp;nbsp;&amp;nbsp;&amp;nbsp; --&amp;gt; [Row 12] BF Ever (No), [Row 11] BF 12M+ (No)&lt;/P&gt;
&lt;P&gt;6 1 0 0 0 0 0 0 0 0 0 0 0&lt;FONT color="#FF0000"&gt; 0&lt;/FONT&gt; 6 1 2004&amp;nbsp;&amp;nbsp;&amp;nbsp; --&amp;gt; [Row 14] BF Ever (No), [Row 13] BF 1Mo (No)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 13:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Data-preparation-for-a-line-chart-and-using-array-index-in/m-p/425217#M68257</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2018-01-05T13:29:43Z</dc:date>
    </item>
  </channel>
</rss>

