📄 m35 - processing variables with arrays - 33 of 35.mht
字号:
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_14.htm">creates the=20
variables</A> for you by concatenating the array name and the =
numbers 1,=20
2, 3 ... up to the array dimension. To create an array of =
character=20
variables, add a dollar sign (<CODE>$</CODE>) after the array =
dimension.=20
By default, all character variables that are created with an ARRAY =
statement are assigned a length of 8; however, you can specify a =
different=20
length after the dollar sign.=20
<P><STRONG>Assigning Initial Values to Arrays</STRONG><BR>To =
assign <A=20
onmouseover=3D"window.status=3D'Display details on assigning =
initial values.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_18.htm">initial=20
values</A> in an ARRAY statement, place the values in parentheses =
after=20
the array elements, specifying one initial value for each array =
element=20
and separating each value with a comma or blank. To assign initial =
values=20
to character variables, enclose each value in quotation marks.=20
<P><STRONG>Creating Temporary Array Elements</STRONG><BR>You can =
create=20
temporary array elements for DATA step processing without creating =
additional variables. Just specify <A=20
onmouseover=3D"window.status=3D'Display details on temporary array =
elements.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_20.htm">_TEMPORARY_</=
A>=20
after the array name and dimension. This is useful when the array =
is=20
needed only to perform a calculation.=20
<P><STRONG>Multidimensional Arrays</STRONG><BR>To define a=20
multidimensional array, specify the number of elements in <A=20
onmouseover=3D"window.status=3D'Display details on =
multidimensional arrays.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_23.htm">each=20
dimension</A>, separated by a comma. For example, =
<NOBR><CODE><FONT=20
color=3D#003399>array new{3,4} x1-x12;</FONT></CODE></NOBR> =
defines a=20
two-dimensional array, with the first dimension specifying the =
number of=20
rows (3) and the second dimension specifying the number of columns =
(4).=20
<P><STRONG>Referencing Elements of a Two-Dimensional=20
Array</STRONG><BR>Multidimensional arrays are typically used with =
nested=20
DO loops. If a DO loop processes a two-dimensional array, you can =
<A=20
onmouseover=3D"window.status=3D'Display details on referencing =
elements of two-dimensional arrays.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_26.htm">reference =
any=20
element</A> within the array by specifying the two dimensions.=20
<P><STRONG>Rotating Data Sets</STRONG><BR>You can use arrays to <A =
onmouseover=3D"window.status=3D'Display details on rotating data =
sets.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_32.htm">rotate =
a data=20
set</A>. Rotating a data set changes variables to observations or=20
observations to variables. </P></TD></TR></TBODY></TABLE><!-- =
InstanceEndEditable --><BR>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" align=3Dcenter =
border=3D0>
<TBODY>
<TR>
<TD align=3Dleft>
<HR>
</TD></TR></TBODY></TABLE>
<P><!-- InstanceBeginEditable name=3D"syntax" -->
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD><STRONG><A name=3DSyntax>Syntax</A></STRONG>=20
<P><EM>To go to the page where a statement or option was =
presented, select=20
a link.</EM>=20
<P>
<BLOCKQUOTE><NOBR><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on ARRAY =
statement syntax.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_3.htm"><STRONG>ARRAY<=
/STRONG>=20
=
<EM>array-name</EM><STRONG>{</STRONG><EM>dimension</EM><STRONG>}</STRONG>=
=20
<EM><elements></EM><STRONG>;</STRONG></A></FONT></NOBR>=20
<P><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on ARRAY =
reference.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_7.htm"><EM>array-name=
</EM><STRONG>(</STRONG><EM>index=20
value</EM><STRONG>)</STRONG></A></FONT>=20
<P><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DIM =
function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m35/m35_11.htm"><STRONG>DIM(<=
/STRONG><EM>array-name</EM><STRONG>)</STRONG></A></FONT>=20
</P></BLOCKQUOTE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft>
<HR>
</TD></TR></TBODY></TABLE><BR></CENTER><!-- InstanceEndEditable -->
<P><!-- InstanceBeginEditable name=3D"sampleprogram" -->
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG><A name=3DSample>Sample =
Programs</A></STRONG> <PRE><FONT color=3D#003399> data =
work.report(drop=3Di);</FONT>
<FONT color=3D#003399> set master.temps;</FONT>
<FONT color=3D#003399> array wkday{7} mon tue wed thr fri sat =
sun;</FONT>
<FONT color=3D#003399> do i=3D1 to 7;</FONT>
<FONT color=3D#003399> =
wkday<CODE>{i}</CODE>=3D5*(wkday<CODE>{i}</CODE>-32)/9;</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> run;</FONT>
<FONT color=3D#003399> data hrd.convert(drop=3Di);</FONT>
<FONT color=3D#003399> set hrd.fitclass;</FONT>
<FONT color=3D#003399> array wt{6} weight1-weight6;</FONT>
<FONT color=3D#003399> do i=3D1 to dim(wt);</FONT>
<FONT color=3D#003399> =
wt<CODE>{i}</CODE>=3Dwt<CODE>{i}</CODE>*2.2046;</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> run;</FONT>
<FONT color=3D#003399> data hrd.diff(drop=3Di);</FONT>
<FONT color=3D#003399> set hrd.convert;</FONT>
<FONT color=3D#003399> array wt{6} weight1-weight6;</FONT>
<FONT color=3D#003399> array WgtDiff{5};</FONT>
<FONT color=3D#003399> do i=3D1 to 5;</FONT>
<FONT color=3D#003399> =
wgtdiff<CODE>{i}</CODE>=3Dwt{i+1{-wt<CODE>{i}</CODE>;</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> run;</FONT>
<FONT color=3D#003399> data finance.report(drop=3Di);</FONT>
<FONT color=3D#003399> set finance.qsales;</FONT>
<FONT color=3D#003399> array sale{4} sales1-sales4;</FONT>
<FONT color=3D#003399> array goal{4} _temporary_ (9000 9300 9600 =
9900);</FONT>
<FONT color=3D#003399> array Achieved{4};</FONT>
<FONT color=3D#003399> do i=3D1 to 4;</FONT>
<FONT color=3D#003399> =
achieved<CODE>{i}</CODE>=3D100*sale<CODE>{i}</CODE>/goal<CODE>{i}</CODE>;=
</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> run;</FONT>
<FONT color=3D#003399> data finance.quarters(drop=3Di j);</FONT>
<FONT color=3D#003399> set finance.monthly;</FONT>
<FONT color=3D#003399> array m{4,3} month1-month12;</FONT>
<FONT color=3D#003399> array Qtr{4};</FONT>
<FONT color=3D#003399> do i=3D1 to 4;</FONT>
<FONT color=3Dblue><STRONG> </STRONG></FONT><FONT =
color=3D#003399>qtr<CODE>{i}</CODE>=3D0;</FONT>
<FONT color=3D#003399> do j=3D1 to 3;</FONT>
<FONT color=3D#003399> qtr<CODE>{i}</CODE>+m{i,j};</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> end;</FONT>
<FONT color=3D#003399> run;</FONT></PRE>
<P>
<HR>
</TD></TR></TBODY></TABLE><BR><!-- InstanceEndEditable -->
<P><!-- InstanceBeginEditable name=3D"pointstoremember" -->
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG><A name=3DPoints>Points to =
Remember</A></STRONG> <BR>
<UL>
<LI>A SAS array exists only for the duration of the DATA step. =
<BR><BR>
<LI>Do not give an array the same name as a variable in the same =
DATA=20
step. Also, avoid using the name of a SAS function as an array =
name; the=20
array will be correct, but you won't be able to use the function =
in the=20
same DATA step, and a warning will be written to the SAS log. =
<BR><BR>
<LI>You can indicate the dimension of a one-dimensional array =
with an=20
asterisk (<CODE>*</CODE>) as long as you specify the elements of =
the=20
array. <BR><BR>
<LI>When referencing array elements, be careful not to confuse =
variable=20
names with the array references. <CODE>WgtDiff1</CODE> through=20
<CODE>WgtDiff5</CODE> is not the same as <CODE>WgtDiff(1)</CODE> =
through=20
<CODE>WgtDiff(5)</CODE>. =
</LI></UL></TD></TR></TBODY></TABLE><!-- InstanceEndEditable =
--></CENTER><!-- #BeginLibraryItem "/Library/nav_regular_bottom.lbi" -->
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%">
<TBODY>
<TR>
<TD width=3D14><IMG height=3D7 alt=3D""=20
=
src=3D"http://www.sas.com/apps/elearning/images/en/navimages/linebox.gif"=
=20
width=3D14></TD>
<TD colSpan=3D2><IMG height=3D7 alt=3D""=20
=
src=3D"http://www.sas.com/apps/elearning/images/en/navimages/linegray.gif=
"=20
width=3D"100%"></TD></TR>
<TR>
<TD> </TD>
<TD vAlign=3Dtop><FONT face=3D"Verdana, Arial, Helvetica, Sans =
Serif"=20
color=3Dgray size=3D1><A class=3Dcopyrightlink=20
href=3D"javascript:%20openOther('../copyrite.htm')"><FONT=20
face=3D"Arial, Helvetica, sans-serif">Copyright</FONT></A> <FONT=20
face=3D"Arial, Helvetica, sans-serif">=A9 2003 SAS Institute Inc., =
Cary, NC,=20
USA. All rights reserved.</FONT></FONT> <FONT=20
face=3D"Arial, Helvetica, sans-serif"><BR><FONT color=3Dgray =
size=3D1><A=20
class=3Dcopyrightlink href=3D"http://www.sas.com/Copyright.html"=20
target=3D_blank>Terms of Use & Legal Information</A> | <A=20
class=3Dcopyrightlink href=3D"http://www.sas.com/Privacy.html"=20
target=3D_blank>Privacy Statement</A></FONT> </FONT></TD>
<TD width=3D60>
<DIV align=3Dright><A=20
onmouseover=3D"rOver('back2');window.status=3D'Display the =
previous page.';return true"=20
accessKey=3Db =
onmouseout=3D"rOut('back2');window.status=3D'';return true"=20
href=3D"javascript:%20prevPage()"><IMG height=3D19 alt=3Dback=20
=
src=3D"http://www.sas.com/apps/elearning/images/en/navimages/back2.gif"=20
width=3D30 border=3D0 name=3Dback2></A><A=20
onmouseover=3D"rOver('next2');window.status=3D'Display the next =
page.';return true"=20
accessKey=3Dn =
onmouseout=3D"rOut('next2');window.status=3D'';return true"=20
href=3D"javascript:%20nextPage()"><IMG height=3D19 alt=3Dnext=20
=
src=3D"http://www.sas.com/apps/elearning/images/en/navimages/next2.gif"=20
width=3D30 border=3D0 =
name=3Dnext2></A></DIV></TD></TR></TBODY></TABLE>
<P> </P>
<SCRIPT>writeLessonDiv()</SCRIPT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -