<?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: Array Function ? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844532#M36694</link>
    <description>&lt;P&gt;AND missed a SET statement to bring any existing data to work with.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 23:17:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-11-15T23:17:31Z</dc:date>
    <item>
      <title>Array Function ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844522#M36691</link>
      <description>&lt;P&gt;I am not really sure what number is supposed to go into the array function.&lt;/P&gt;&lt;P&gt;These are the variables + the site_id I created.&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Variable&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Description&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;subj_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Subject ID&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;phy_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;physician ID&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Fracture&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1 = yes, 0 = no&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;momfrac&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Mother had hip fracture&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;raterisk&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;self reported risk of fracture relative to others of the same age(same, less, greater,NA=missing)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;priorfrac&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;history of prior fractures&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;age&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;subject age&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;height&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;height in cm at enrollment&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;weight&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;weight in kg at enrollment&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7';
run; 
data glow_combined; 
set hw7.glow1 
hw7.glow2
hw7.glow3
hw7.glow4
hw7.glow5 
hw7.glow6; 
run;
data glow_combined; 
set hw7.glow1(in= glow1) 
hw7.glow2 (in=glow2)
hw7.glow3 (in=glow3) 
hw7.glow4 (in=glow4) 
hw7.glow5 (in=glow5)
hw7.glow6 (in=glow6); 
if glow1 then site_id  = 1;
if glow2 then site_id  = 2;
if glow3 then site_id = 3; 
if glow4 then site_id = 4;
if glow5 then site_id = 5;
if glow6 then site_id = 6;
run;
data glow_combined;
array miss[10] age weight weight;
do i = 1 to 10;
	if miss[i] = 999 then miss[i] = .;
end;
if miss[10] = 99 then miss[10] = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;This is the error code I received: &lt;BR /&gt;&lt;BR /&gt;148  libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7';
NOTE: Libref HW7 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7
149  run;
150  data glow_combined;
151  set hw7.glow1
152  hw7.glow2
153  hw7.glow3
154  hw7.glow4
155  hw7.glow5
156  hw7.glow6;
157  run;

NOTE: There were 107 observations read from the data set HW7.GLOW1.
NOTE: There were 90 observations read from the data set HW7.GLOW2.
NOTE: There were 65 observations read from the data set HW7.GLOW3.
NOTE: There were 36 observations read from the data set HW7.GLOW4.
NOTE: There were 120 observations read from the data set HW7.GLOW5.
NOTE: There were 82 observations read from the data set HW7.GLOW6.
NOTE: The data set WORK.GLOW_COMBINED has 500 observations and 9 variables.
NOTE: DATA statement used (Total process time):
      real time           0.14 seconds
      cpu time            0.03 seconds


158  data glow_combined;
159  set hw7.glow1(in= glow1)
160  hw7.glow2 (in=glow2)
161  hw7.glow3 (in=glow3)
162  hw7.glow4 (in=glow4)
163  hw7.glow5 (in=glow5)
164  hw7.glow6 (in=glow6);
165  if glow1 then site_id  = 1;
166  if glow2 then site_id  = 2;
167  if glow3 then site_id = 3;
168  if glow4 then site_id = 4;
169  if glow5 then site_id = 5;
170  if glow6 then site_id = 6;
171  run;

NOTE: There were 107 observations read from the data set HW7.GLOW1.
NOTE: There were 90 observations read from the data set HW7.GLOW2.
NOTE: There were 65 observations read from the data set HW7.GLOW3.
NOTE: There were 36 observations read from the data set HW7.GLOW4.
NOTE: There were 120 observations read from the data set HW7.GLOW5.
NOTE: There were 82 observations read from the data set HW7.GLOW6.
NOTE: The data set WORK.GLOW_COMBINED has 500 observations and 10 variables.
NOTE: DATA statement used (Total process time):
      real time           0.12 seconds
      cpu time            0.00 seconds


172  data glow_combined;
173  array miss[10] age weight weight;
ERROR: Too few variables defined for the dimension(s) specified for the array miss.
174  do i = 1 to 10;
175      if miss[i] = 999 then miss[i] = .;
176  end;
177  if miss[10] = 99 then miss[10] = .;
178  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      175:8   177:4
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.GLOW_COMBINED may be incomplete.  When this step was stopped there were 0
         observations and 1 variables.
WARNING: Data set WORK.GLOW_COMBINED was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 22:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844522#M36691</guid>
      <dc:creator>MisterJenn</dc:creator>
      <dc:date>2022-11-15T22:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Array Function ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844527#M36692</link>
      <description>&lt;PRE&gt;172  data glow_combined;
173  array miss[10] age weight weight;
ERROR: Too few variables defined for the dimension(s) specified for the array miss.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You defined an array with 10 elements, and then listed only 3. You probably want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data glow_combined;
array miss[3] age weight weight;
do i = 1 to 3;
   if miss[i] = 999 then miss[i] = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that you have entered the variable WEIGHT twice into the array. I doubt that is what you want, it doesn't even make sense in an array; and I don't even know if that will work.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 22:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844527#M36692</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-15T22:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Array Function ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844530#M36693</link>
      <description>&lt;PRE&gt;libname hw7 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Homework 7';

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*This is not needed;&lt;/STRONG&gt;&lt;/FONT&gt;
run; 


data glow_combined; 
set hw7.glow1 
hw7.glow2
hw7.glow3
hw7.glow4
hw7.glow5 
hw7.glow6; 
run;

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*this data set is the same names as the data set created in the previous data step and will overwrite it;&lt;/STRONG&gt;&lt;/FONT&gt;
data glow_combined; 
set hw7.glow1(in= glow1) 
hw7.glow2 (in=glow2)
hw7.glow3 (in=glow3) 
hw7.glow4 (in=glow4) 
hw7.glow5 (in=glow5)
hw7.glow6 (in=glow6); 

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*this should be IF/ELSE IF not a series of IF;&lt;/STRONG&gt;&lt;/FONT&gt;
if glow1 then site_id  = 1;
if glow2 then site_id  = 2;
if glow3 then site_id = 3; 
if glow4 then site_id = 4;
if glow5 then site_id = 5;
if glow6 then site_id = 6;
run;

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*This will once again overwrite the data set created in the previous step;&lt;/STRONG&gt;&lt;/FONT&gt;
data glow_combined;

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*there is no input data set specified (no set statement);&lt;/STRONG&gt;

&lt;STRONG&gt;*there are 3 variables but a dimension set of 10. Need to list ten variables or change the dimension to 10;
*do not use the word miss as an array name as SAS has a function missing and this could get confusing;&lt;/STRONG&gt;&lt;/FONT&gt;
array miss[10] age weight weight;

&lt;FONT color="#FF0000"&gt;*change the loop to match the number of variables in the array;&lt;/FONT&gt;
do i = 1 to 10;
	if miss[i] = 999 then miss[i] = .;
end;

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;*works only the 10th variable in the list, which is non existent at the moment;&lt;/STRONG&gt;&lt;/FONT&gt;
if miss[10] = 99 then miss[10] = .;
run;&lt;/PRE&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I commented your code with the issues highlighted in red.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 23:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844530#M36693</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-15T23:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Array Function ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844532#M36694</link>
      <description>&lt;P&gt;AND missed a SET statement to bring any existing data to work with.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 23:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844532#M36694</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-15T23:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Array Function ?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844536#M36695</link>
      <description>&lt;P&gt;There is no ARRAY() function.&amp;nbsp; There is an ARRAY statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are talking about the dimension of the array you don't need to supply any value for that. SAS can COUNT.&amp;nbsp; You don't need anything there at all.&amp;nbsp; Use the DIM() function (that is an actual function) to find the number of variables that the array is referencing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array miss age height weight;
do i = 1 to dim(miss);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So assuming that someone made the mistake of designing your data entry system so that missing values are recorded as actual numbers and the goal is to recode those values to missing then just do each variable by itself.&amp;nbsp; If you have more then 5 variables that all used the same valid number to represent missing then perhaps it is worth making an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for this problem there is no need to use an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if age=999 then age=.;
if height=99 then height=.;
if weight=999 then weight=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 03:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Array-Function/m-p/844536#M36695</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-16T03:18:18Z</dc:date>
    </item>
  </channel>
</rss>

