<?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 Where do arrays come in on this task? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948687#M371160</link>
    <description>&lt;P&gt;I have a data set that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data SurgerySatisfaction;
	input ID$ Knee_1or2$ Score_PreOp Score_1Day Score_1Week Score_1Month;
	cards;
	    01 1 0 5 7 10
	    02 1 0 10 15 15
	    02 2 3 5 8 10
	    03 1 0 3 3 3
	    03 2 0 6 9 9
	    04 1 0 4 10 10
	;
run;&lt;/PRE&gt;&lt;P&gt;Basically, the data set records patient ID, which knee got replacement surgery (1 or 2), and satisfaction scores at a certain time before/after the surgery.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The task then asked to use the array staatement to create a new data set that contains satisfaction scores for knee 1, and the output is supposed to look like this:&lt;/P&gt;&lt;PRE&gt;id    visit    score

01      1         0
01      2         5
01      3         7
01      4        10
02      1         0
02      2        10
02      3        15
02      4        15
03      1         0
03      2         3
03      3         3
03      4         3
04      1         0
04      2         4
04      3        10
04      4        10&lt;/PRE&gt;&lt;P&gt;How is this acheived by the array statement? I guess I also need to better understand what the whole point of array statements is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Oct 2024 02:21:39 GMT</pubDate>
    <dc:creator>unwashedhelimix</dc:creator>
    <dc:date>2024-10-23T02:21:39Z</dc:date>
    <item>
      <title>Where do arrays come in on this task?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948687#M371160</link>
      <description>&lt;P&gt;I have a data set that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data SurgerySatisfaction;
	input ID$ Knee_1or2$ Score_PreOp Score_1Day Score_1Week Score_1Month;
	cards;
	    01 1 0 5 7 10
	    02 1 0 10 15 15
	    02 2 3 5 8 10
	    03 1 0 3 3 3
	    03 2 0 6 9 9
	    04 1 0 4 10 10
	;
run;&lt;/PRE&gt;&lt;P&gt;Basically, the data set records patient ID, which knee got replacement surgery (1 or 2), and satisfaction scores at a certain time before/after the surgery.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The task then asked to use the array staatement to create a new data set that contains satisfaction scores for knee 1, and the output is supposed to look like this:&lt;/P&gt;&lt;PRE&gt;id    visit    score

01      1         0
01      2         5
01      3         7
01      4        10
02      1         0
02      2        10
02      3        15
02      4        15
03      1         0
03      2         3
03      3         3
03      4         3
04      1         0
04      2         4
04      3        10
04      4        10&lt;/PRE&gt;&lt;P&gt;How is this acheived by the array statement? I guess I also need to better understand what the whole point of array statements is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 02:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948687#M371160</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-10-23T02:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Where do arrays come in on this task?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948690#M371161</link>
      <description>&lt;P&gt;Given this is an exercise we shouldn't just give you the solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below demo2 sample code shows you how to use an array statement to restructure your data from a wide to a long structure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The demo1 sample code demonstrates how you would need to write such code without an array. I hope that explains to you the main purpose of a SAS array: It allows you to loop over variables without having to spell them out one by one. Just think how the demo1 code would need to look like if there were 40 variables.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id var_1 $ var_2 $ var_3 $ var_4 $;
  datalines;
1 A1 A2 A3 A4
2 B1 B2 B3 B4
;

data demo1;
  set have;
  var=var_1; output;
  var=var_2; output;
  var=var_3; output;
  var=var_4; output;
  drop var_1 - var_4;
run;

data demo2;
  set have;
  array vars {*} var_1 - var_4;
  do i=1 to dim(vars);
    var=vars[i];
    output;
  end;
  drop i var_1 - var_4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 02:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948690#M371161</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-23T02:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Where do arrays come in on this task?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948693#M371163</link>
      <description>&lt;P&gt;Ahh, I see. I managed to code an array, but it outputs the scores for both Knee 1 and Knee 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to implement a conditional statement, where it's like "if Knee_1or2 = 2, then do not include this row in the output?"&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 04:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948693#M371163</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-10-23T04:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Where do arrays come in on this task?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948694#M371164</link>
      <description>&lt;P&gt;Ohp, I got it. Disregard!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 04:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-do-arrays-come-in-on-this-task/m-p/948694#M371164</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-10-23T04:08:12Z</dc:date>
    </item>
  </channel>
</rss>

