📄 m14 - reading sas data sets - 30 of 32.mht
字号:
variables, FIRST. and LAST. When you specify <A=20
onmouseover=3D"window.status=3D'Display details on multiple BY =
variables.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_11.htm">multiple BY=20
variables</A>, a change in the value of a primary BY variable =
forces=20
<CODE>LAST.<EM>variable</EM></CODE> to equal <EM>1</EM> for the =
secondary=20
BY variables.=20
<P><STRONG>Reading Observations Using Direct Access</STRONG><BR>In =
addition to reading input data sequentially, you can <A=20
onmouseover=3D"window.status=3D'Display details on the POINT=3D =
option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_14.htm">access =
observations directly</A> by using the POINT=3D option to go =
directly to a=20
data set observation. There is no end-of-file condition when you =
use=20
direct access, so include an explicit <A=20
onmouseover=3D"window.status=3D'Display details on the OUTPUT =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_16.htm">OUTPUT =
statement</A> and then the <A=20
onmouseover=3D"window.status=3D'Display details on the STOP =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_15.htm">STOP=20
statement</A> to prevent continuous looping.=20
<P><STRONG>Detecting the End of a Data Set</STRONG><BR>To =
determine when=20
the <A onmouseover=3D"window.status=3D'Display details on the =
END=3D option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_17.htm">last=20
observation</A> in an input data set has been read, use the END=3D =
option in=20
the SET statement. The specified variable is initialized to =
<EM>0</EM>,=20
then set to <EM>1</EM> when the SET statement reads the last =
observation=20
of the data set. </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>
<DL>
<DT><FONT color=3D#003399><STRONG>LIBNAME</STRONG> =
<EM>libref</EM>=20
=
<STRONG>'</STRONG><EM>SAS-data-library</EM><STRONG>';</STRONG></FONT>=20
<DT><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the DATA =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_2.htm"><STRONG>DATA</=
STRONG>=20
<EM><SAS-data-set></EM></A> <A=20
onmouseover=3D"window.status=3D'Display details on the KEEP=3D =
option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_7.htm">(<STRONG>KEEP=3D=
=20
</STRONG><EM>variable-1=20
<...variable-n></EM>)<STRONG>;</STRONG></A></FONT>=20
<DD><NOBR><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the SET =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_2.htm"><STRONG>SET</S=
TRONG>=20
<EM>SAS-data-set</EM></A> <A=20
onmouseover=3D"window.status=3D'Display details on the DROP=3D =
option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_7.htm">(<STRONG>DROP=3D=
</STRONG>=20
<EM>variable-1 <...variable-n></EM>)</A></FONT></NOBR>=20
=
<DD><NOBR> <FONT=20
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the =
POINT=3D option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_14.htm"><STRONG>POINT=
=3D</STRONG><EM>variable</EM></A>=20
| <A=20
onmouseover=3D"window.status=3D'Display details on the END=3D =
option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_17.htm"><STRONG>END=3D=
</STRONG><EM>variable</EM><STRONG>;</STRONG></A></FONT></NOBR>=20
<DD><A=20
onmouseover=3D"window.status=3D'Display details on the OUTPUT =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_16.htm"><FONT=20
color=3D#003399><STRONG>OUTPUT</STRONG>=20
<<EM>SAS-data-set</EM>><STRONG>;</STRONG></FONT></A>=20
<DD><A=20
onmouseover=3D"window.status=3D'Display details on the STOP =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m14/m14_15.htm"><FONT=20
color=3D#003399><STRONG>STOP;</STRONG></FONT></A>=20
<DT><FONT color=3D#003399><STRONG>RUN;</STRONG></FONT>=20
</DT></DL></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 =
Program</A></STRONG> <PRE> <FONT color=3D#003399>proc sort =
data=3Dcompany.usa out=3Dwork.temp2;</FONT>
<FONT color=3D#003399>by manager jobtype;</FONT>
<FONT color=3D#003399>data company.budget2(keep=3Dmanager jobtype =
payroll);</FONT>
<FONT color=3D#003399>set work.temp2;</FONT>
<FONT color=3D#003399>by manager jobtype;</FONT>
<FONT color=3D#003399>if wagecat=3D'S' then =
Yearly=3Dwagerate*12;</FONT>
<FONT color=3D#003399>else if wagecat=3D'H' then =
Yearly=3Dwagerate*2000;</FONT>
<FONT color=3D#003399>if first.jobtype then Payroll=3D0;</FONT>
<FONT color=3D#003399>payroll+yearly;</FONT>
<FONT color=3D#003399>if last.jobtype;</FONT>
<FONT color=3D#003399>run;</FONT>
<FONT color=3D#003399>data work.getobs5(drop=3Dobsnum);</FONT>
<FONT color=3D#003399>obsnum=3D5;</FONT>
<FONT color=3D#003399>set company.usa(keep=3Dmanager payroll) =
point=3Dobsnum;</FONT>
<FONT color=3D#003399>output;</FONT>
<FONT color=3D#003399>stop;</FONT>
<FONT color=3D#003399>run;</FONT>
<FONT color=3D#003399>data work.addtoend(drop=3Dtimemin =
timesec);</FONT>
<FONT color=3D#003399>set clinic.stress2(keep=3Dtimemin timesec) =
end=3Dlast;</FONT>
<FONT color=3D#003399>TotalMin+timemin;</FONT>
<FONT color=3D#003399>TotalSec+timesec;</FONT>
<FONT color=3D#003399>TotalTime=3Dtotalmin*60+timesec;</FONT>
<FONT color=3D#003399>if last;</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>=20
<UL>
<LI>When you perform BY-group processing, the data sets listed =
in the=20
SET statement must either be sorted by the values of the BY =
variable(s),=20
or they must have an appropriate index.<BR><BR>
<LI>When using direct access to read data, you =
<STRONG>must</STRONG>=20
prevent continuous looping. Add a STOP statement to the DATA =
step, or=20
use programming logic that checks for an invalid value of the =
POINT=3D=20
variable.<BR><BR>
<LI>Do not specify the END=3D option with the POINT=3D option in =
a SET=20
statement.=20
</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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -