📄 m39 - creating and managing variables - 34 of 36.mht
字号:
creating a=20
new variable, SAS allocates as many bytes of storage space as =
there are=20
characters in the <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on variable =
length.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_15.htm">first=20
value</A></FONT> that it encounters for that variable. This can =
result in=20
truncated values. You can use the <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the LENGTH =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_16.htm">LENGTH =
statement</A></FONT> to specify a length before the variable's =
first value=20
is referenced in the DATA step.=20
<P><STRONG>Subsetting Data</STRONG><BR>To omit observations as you =
read=20
raw data, include the <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DELETE =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_18.htm">DELETE =
statement</A></FONT> in an IF-THEN statement. If you need to read =
and=20
process variables that you don't want to keep in the data set, use =
the=20
<FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DROP=3D and =
KEEP=3D data set options.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_20.htm">DROP=3D and =
KEEP=3D=20
data set options</A></FONT> or the <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DROP and =
KEEP statements.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_22.htm">DROP =
and KEEP=20
statements</A></FONT>.=20
<P><STRONG>Assigning Permanent Labels and Formats</STRONG><BR>You =
can use=20
<FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on labels and =
formats.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_26.htm">LABEL =
and FORMAT=20
statements</A></FONT> in DATA steps to permanently assign labels =
and=20
formats. These do not affect how data is stored in the data set, =
only how=20
it appears in output.=20
<P><STRONG>Assigning Values Conditionally Using SELECT=20
Groups</STRONG><BR>As an alternative to IF-THEN/ELSE statements, =
you can=20
use <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on labels and =
formats.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_28.htm">SELECT =
groups</A></FONT> in DATA steps to perform conditional processing. =
SELECT=20
groups are more efficient that IF-THEN/ELSE statements when you =
have a=20
long series of mutually exclusive conditions.=20
<P><STRONG>Grouping Statements Using DO Groups</STRONG><BR>You can =
execute=20
a group of statements as a unit by <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on DO groups.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_32.htm">DO=20
groups</A></FONT> in DATA steps. You can use DO groups in =
IF-THEN/ELSE=20
statements and SELECT groups to perform many statements as part of =
the=20
conditional=20
action.</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><EM></EM>=20
<BLOCKQUOTE>
<DL>
<DT><FONT color=3D#003399><STRONG>LIBNAME</STRONG> =
<EM>libref</EM>=20
<STRONG>'</STRONG><EM>SAS-data-library</EM><STRONG>';</STRONG> =
</FONT>
<DT><FONT color=3D#003399><STRONG>FILENAME</STRONG> =
<EM>fileref</EM>=20
<STRONG>'</STRONG><EM>filename</EM><STRONG>';</STRONG> </FONT>
<DT><FONT color=3D#003399><STRONG>DATA</STRONG> =
<EM>SAS-data-set</EM> <A=20
onmouseover=3D"window.status=3D'Display details on the DROP=3D =
and KEEP=3D data set options.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_20.htm"><STRONG>(DROP=
=3D</STRONG><EM>variable(s)</EM>|<STRONG>KEEP=3D</STRONG><EM>variable(s)<=
/EM><STRONG>)</STRONG></A><STRONG>;</STRONG>=20
</FONT>
<DD><FONT color=3D#003399><STRONG>INFILE</STRONG>=20
<EM>file-specification</EM>=20
<<STRONG>OBS=3D</STRONG><EM>n</EM>><STRONG>;</STRONG> =
</FONT>
<DD><FONT color=3D#003399><STRONG>INPUT</STRONG> =
<EM>variable</EM>=20
<<STRONG>$</STRONG>>=20
<EM>startcol-endcol</EM>...<STRONG>;</STRONG> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DROP =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_22.htm"><STRONG>DROP<=
/STRONG>=20
<EM>variable(s)</EM><STRONG>;</STRONG></A> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the KEEP =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_22.htm"><STRONG>KEEP<=
/STRONG>=20
<EM>variable(s)</EM><STRONG>;</STRONG></A> </FONT>
<DD><FONT color=3D#003399><NOBR><A=20
onmouseover=3D"window.status=3D'Display details on =
initializing sum variables.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_5.htm"><STRONG>RETAIN=
</STRONG>=20
<EM>variable initial-value</EM><STRONG>;</STRONG></A></NOBR> =
</FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the sum =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_2.htm"><EM>variable+e=
xpression</EM><STRONG>;</STRONG></A>=20
</FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the LENGTH =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_16.htm"><STRONG>LENGT=
H</STRONG>=20
<EM>variable(s) </EM><$><EM> =
length</EM><STRONG>;</STRONG></A>=20
</FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the IF-THEN =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_8.htm"><STRONG>IF</ST=
RONG>=20
<EM>expression</EM> <STRONG>THEN</STRONG>=20
<EM>statement</EM><STRONG>;</STRONG></A> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the ELSE =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_13.htm"><STRONG>ELSE<=
/STRONG>=20
<EM>statement</EM><STRONG>;</STRONG></A> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the IF-THEN =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_18.htm"><STRONG>IF</S=
TRONG>=20
<EM>expression</EM> <STRONG>THEN DELETE</STRONG>;</A> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the LABEL =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_26.htm"><STRONG>LABEL=
</STRONG>=20
=
<EM>variable1</EM><STRONG>=3D'</STRONG><EM>label1</EM><STRONG>'</STRONG> =
=
<EM>variable2</EM><STRONG>=3D'</STRONG><EM>label2</EM><STRONG>'</STRONG> =
...<STRONG>;</STRONG></A></FONT>=20
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the FORMAT =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_26.htm"><STRONG>FORMA=
T</STRONG>=20
<EM>variable(s) format-name</EM>;</A></FONT>=20
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the SELECT =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_28.htm"><STRONG>SELEC=
T</STRONG>=20
<EM><(select-expression)></EM>;</A> </FONT>
<DD><FONT =
color=3D#003399> <A=20
onmouseover=3D"window.status=3D'Display details on the WHEN =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m39/m39_28.htm"><STRONG>WHEN<=
/STRONG><EM>-</EM>1<EM>=20
(when-expression-1 <..., when-expression-n>) statement;=20
</EM><STRONG>;</STRONG></A></FONT>=20
<DD><FONT =
color=3D#003399> <A=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -