📄 m12 - creating sas data sets from raw data - 46 of 48.mht
字号:
onmouseover=3D"window.status=3D'Display details on referencing a =
raw data file.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_6.htm">reference the =
raw=20
data file</A></FONT> by creating a fileref. Just as you assign a =
libref by=20
using a LIBNAME statement, you assign a fileref by using a =
FILENAME=20
statement.
<SCRIPT>writeInterface(docInfo1);</SCRIPT>
=20
<P><STRONG>Writing a DATA Step Program</STRONG><BR>The DATA =
statement=20
indicates the beginning of the DATA step and <FONT =
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on naming the data =
set.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_11.htm">names =
the SAS=20
data set</A></FONT> to be created.=20
<P>Next, you <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on specifying the =
raw data file.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_13.htm">specify the =
raw=20
data file</A></FONT> by using the INFILE statement. The OBS=3D =
option in the=20
INFILE statement enables you to process a specified number of=20
observations.=20
<P>This lesson teaches <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on listing the =
data set.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_14.htm">column =
input</A></FONT>, the most common input style. Column input =
specifies=20
actual column locations for data values. The INPUT statement <FONT =
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on describing the =
data.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_15.htm">describes =
the=20
raw data</A></FONT> to be read and placed into the SAS data set.=20
<P><STRONG>Submitting the Program</STRONG><BR>When you submit the =
program,=20
you can use the OBS=3D option with the INFILE statement to <FONT=20
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on verifying the =
data.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_19.htm">verify =
that the=20
correct data</A></FONT> is being read before reading the entire =
data file.=20
<P>After you submit the program, view the log to <FONT =
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on checking DATA =
step processing.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_22.htm">check =
the DATA=20
step processing</A></FONT>. You can then <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on listing the =
data set.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_23.htm">list =
the data=20
set</A></FONT> by using the PROC PRINT procedure.=20
<P>Once you've checked the log and verified your data, you can =
modify the=20
DATA step to <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on reading the =
entire raw data file.'; "=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_25.htm">read =
the entire=20
raw data file</A></FONT> by removing the OBS=3D option from the =
INFILE=20
statement.=20
<P>If you are working with a raw data file that contains <FONT=20
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on invalid =
data.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_27.htm">invalid=20
data</A></FONT>, the DATA step continues to execute. Unlike syntax =
errors,=20
invalid data errors do not cause SAS to stop processing a program. =
If you=20
have a way to edit the invalid data, it's best to correct the =
problem and=20
rerun the DATA step.=20
<P><STRONG>Creating and Modifying Variables</STRONG><BR>To modify =
existing=20
values or to create new variables, you can use an <FONT =
color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the assignment =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_30.htm">assignment=20
statement</A></FONT> in any DATA step. Within assignment =
statements, you=20
can specify any <A=20
onmouseover=3D"window.status=3D'Display details on SAS =
expressions.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_30.htm#express">SAS=20
expression</A>.=20
<P>You can use <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on arithmetic =
operators and date constants.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_32.htm">date=20
constants</A></FONT> to assign dates in assignment statements. You =
can=20
also use SAS time constants and SAS datetime constants in =
assignment=20
statements.=20
<P><STRONG>Subsetting Data</STRONG><BR>To process only =
observations that=20
meet a specified condition, use a <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the subsetting =
IF statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_35.htm">subsetting =
IF=20
statement</A></FONT> in the DATA step.=20
<P><STRONG>Reading Instream Data</STRONG><BR>To read instream data =
lines=20
instead of an external file, use a <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the CARDS =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_37.htm">DATALINES=20
statement</A></FONT> or a CARDS statement and enter data directly =
in your=20
SAS program. Omit the RUN at the end of the DATA step.=20
<P><STRONG>Creating a Raw Data File</STRONG><BR>When the goal of =
your SAS=20
program is to create a raw data file and not a SAS data set, it is =
inefficient to list a data set name in the DATA statement. Instead =
use the=20
keyword <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the _NULL_ =
keyword.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_39.htm">_NULL_</A></F=
ONT>,=20
which allows the power of the DATA step without actually creating =
a SAS=20
data set. A SET statement specifies the SAS data set that you want =
to read=20
from.=20
<P>You can use the <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the FILE =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_40.htm">FILE</A></FON=
T>=20
and <FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the PUT =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_41.htm">PUT</A></FONT=
>=20
statements to write out the observations from a SAS data set to a =
raw data=20
file just as you used the INFILE and INPUT statements to create a =
SAS data=20
set. These two sets of statements work almost identically.=20
</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><STRONG>Reading Data from an External File or Reading Instream=20
Data</STRONG>=20
<BLOCKQUOTE>
<DL>
<DT><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the LIBNAME =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_4.htm"><STRONG>LIBNAM=
E</STRONG>=20
<EM>libref</EM>=20
=
<STRONG>'</STRONG><EM>SAS-data-library</EM><STRONG>';</STRONG></A>=20
</FONT>
<DT><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the =
FILENAME statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_6.htm"><STRONG>FILENA=
ME</STRONG>=20
<EM>fileref</EM>=20
<STRONG>'</STRONG><EM>filename</EM><STRONG>';</STRONG></A> =
</FONT>
<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/m12/m12_11.htm"><STRONG>DATA<=
/STRONG>=20
<EM>SAS-data-set</EM>;</A> </FONT>
<DD><FONT color=3D#003399><A=20
onmouseover=3D"window.status=3D'Display details on the INFILE =
statement.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
=
href=3D"http://www.sas.com/apps/OLTRN/59080/m12/m12_13.htm"><STRONG>INFIL=
E</STRONG>=20
<EM>file-specification</EM></A> <A=20
onmouseover=3D"window.status=3D'Display details on the OBS=3D =
option.';"=20
onclick=3DsuggestBack() onmouseout=3D"window.status=3D''"=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -