📄 m30 - transforming data with sas functions - 93 of 95.mht
字号:
original numeric values are not changed; the conversion creates =
temporary=20
character values and places a note in the SAS=20
log.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>Explicit Numeric-to-Character=20
Conversion</STRONG><BR>The <A=20
onmouseover=3D"window.status=3D'Display details on the PUT =
function.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_19.htm">PUT =
function</A>=20
provides direct, controlled conversion of numeric values to =
character=20
values. The format specified in a PUT function must match the =
source, so=20
use an appropriate numeric format to create the new character =
values. No=20
note will appear in the SAS =
log.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>SAS Date and Time Values</STRONG><BR>SAS <A =
onmouseover=3D"window.status=3D'Display details on SAS date and =
time values.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_25.htm">date =
values</A>=20
are stored as the number of days from January 1, 1960; time values =
are=20
stored as the number of seconds since midnight. These values can =
be=20
displayed in a variety of forms by associating them with SAS=20
formats.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD><STRONG>YEAR, QTR, MONTH, and DAY Functions</STRONG><BR>To =
extract the=20
<A=20
onmouseover=3D"window.status=3D'Display details on the YEAR, =
MONTH, and DAY functions.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_28.htm">year, =
quarter,=20
month, or day value</A> from a SAS date value, specify the YEAR, =
QTR,=20
MONTH, or DAY function followed by the SAS date value in =
parentheses. The=20
YEAR function returns a four-digit number; QTR returns a value of =
1, 2, 3,=20
or 4; MONTH returns a number from 1 to 12; and DAY returns 1 to=20
31.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>WEEKDAY Function</STRONG><BR>To extract the =
<A=20
onmouseover=3D"window.status=3D'Display details on the WEEKDAY =
function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_40.htm">day of =
the=20
week</A> from a SAS date value, specify the function WEEKDAY =
followed by=20
the SAS date value in parentheses. The function returns a numeric =
value=20
from 1 to 7, representing the day of the=20
week.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>MDY Function</STRONG><BR>To <A=20
onmouseover=3D"window.status=3D'Display details on the MDY =
function.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_42.htm">create =
a SAS=20
date value</A> for a month, day, and year, specify the MDY =
function=20
followed by the date values. The result can be displayed in =
several ways=20
by applying a SAS date format. SAS interprets two-digit values =
according=20
to the 100-year span that is set by the YEARCUTOFF=3D system =
option. The=20
default value of YEARCUTOFF=3D is =
1920.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>DATE and TODAY Functions</STRONG><BR>To <A=20
onmouseover=3D"window.status=3D'Display details on the DATE and =
TODAY functions.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_46.htm">convert the=20
current date</A> to a SAS date value, specify the DATE or TODAY =
function=20
without arguments. The DATE and TODAY functions can be used=20
interchangeably.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD><STRONG>INTCK Function</STRONG><BR>To count the number of <A=20
onmouseover=3D"window.status=3D'Display details on the INTCK =
function.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_48.htm">time=20
intervals</A> that occur in a time span, use the INTCK function =
and=20
specify the interval constant or variable, the beginning date =
value, and=20
the ending date value. The INTCK function counts intervals from =
fixed=20
interval beginnings, not in multiples of an interval unit. Partial =
intervals are not counted.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD><STRONG>INTNX Function</STRONG><BR>To apply <A=20
onmouseover=3D"window.status=3D'Display details on the INTNX =
function.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_52.htm">multiples of =
an=20
interval</A> to a date value, use the INTNX function and specify =
the=20
interval constant or variable, the start-from date value, and the=20
increment. Include the alignment option to specify whether the =
date=20
returned should be at the beginning, middle, or end of the=20
interval.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD><STRONG>SCAN Function</STRONG><BR>The SCAN function <A=20
onmouseover=3D"window.status=3D'Display details on the SCAN =
function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_56.htm">separates a=20
character string</A> to return a word based on its position. It =
defines=20
words by counting delimiters, which are characters that are used =
as word=20
separators. The name of the function is followed, in parentheses, =
by the=20
name of the character variable, the number of delimiters to count, =
and the=20
specified delimiters enclosed in quotation=20
marks.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>SUBSTR Function</STRONG><BR>The SUBSTR =
function can=20
be used to <A=20
onmouseover=3D"window.status=3D'Display details on extracting =
values with the SUBSTR function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_65.htm">extract</A> =
or=20
<A=20
onmouseover=3D"window.status=3D'Display details on replacing =
values with the SUBSTR function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_70.htm">replace</A> =
any=20
portion of a character string. To extract values, place the =
function on=20
the right side of an assignment statement and specify, in =
parentheses, the=20
name of the character variable, the starting character position, =
and the=20
number of characters to extract. To replace values, place the =
function on=20
the left side of an assignment statement and specify, in =
parentheses, the=20
name of the variable being modified, the starting character =
position, and=20
the number of characters to =
replace.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>SCAN versus SUBSTR</STRONG><BR>Both the <A=20
onmouseover=3D"window.status=3D'Display details on SCAN versus =
SUBSTR.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_63.htm">SCAN =
and=20
SUBSTR</A> functions can extract a substring from a character =
value. SCAN=20
relies on delimiters, whereas SUBSTR reads values from specified=20
locations. Use SCAN when you know the delimiter and the order of =
words.=20
Use SUBSTR when the positions of the characters don't=20
vary.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>TRIM Function</STRONG><BR>Because SAS pads =
the=20
length of character values, unwanted spaces can sometimes appear =
after=20
strings are concatenated. To <A=20
onmouseover=3D"window.status=3D'Display details on the TRIM =
function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_75.htm">remove =
trailing=20
blanks</A> from character values, specify the TRIM function with =
the name=20
of a character variable. Remember that trimmed values will be =
padded with=20
blanks again if they are shorter than the length of the new=20
variable.</TD></TR></TBODY></TABLE></CENTER>
<P align=3Dcenter>
<CENTER>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"85%" border=3D0>
<TBODY>
<TR>
<TD align=3Dleft><STRONG>INDEX Function</STRONG><BR>To <A=20
onmouseover=3D"window.status=3D'Display details on the INDEX =
function.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m30/m30_78.htm">test =
character=20
values</A> for the presence of a string, use the INDEX function =
and=20
specify, in parentheses, the name of the variable and the string =
enclosed=20
in quotation marks. The INDEX function can be used with an IF =
statement=20
when you are creating a data set. However, only those observations =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -