加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

SAS数据的输入&输出

(2012-09-13 17:26:35)
标签:

教育

分类: 03SAS数据处理
混合数据模型:常数和变量都放在common里面;
变截距模型:变量输入common里面;
变系数模型:c和变量都要放在cross—section specific里面。

http://www.ejxjy.com/ http://www.ejxjy.com/  师大培训中心 63340811邮箱
https://www.enetedu.com/ https://www.enetedu.com/ jung@163邮箱


Reading Data into SAS


This page was adapted from a page created by Oliver Schabenberger.  We thank Professor Schabenberger for permission to adapt and distribute this page via our web site.


1. Reading data inline 
2. Reading data with column pointers 
3. Reading data from ASCII files 
4. Reading dBase files 
5. Creating a permanent data set 
6. Reading Excel files into SAS

  http://s13/mw690/001Rt2X3gy6VwwmMw7qac&690


1.      SAS 数据的输入&输出.TXT .DAT .XLS .MDB .SAV格式)

一、导入导出文本文件(txt格式)、纯数据文件(dat格式);其实都是导入导出DLM文件(*.*),需要指定分隔符号。

 

1.TAB分割,第一行为变量名(txt为例,dat同样)

PROC IMPORT OUT=A

            DATAFILE= "D:\cha\1.txt"

            DBMS=TAB REPLACE;

     GETNAMES=YES;

     DATAROW=2;

RUN;

 

PROC EXPORT DATA=A

            OUTFILE= "D:\filelist.txt"

            DBMS=TAB REPLACE;

RUN;


DATA toads;

INFILE ’c:\MyRawData\ToadJump.dat’;

INPUT ToadName $ Weight Jump1 Jump2 Jump3;

RUN;

http://blog.sina.com.cn/s/blog_65abf1890100qthq.html

The following is a typical INFILE statement:

INFILE "C:\sasfiles\testfile.csv" DLM='09'x DSD LRECL=1024 TRUNCOVER FIRSTOBS=2;

 

The INPUT statement is used to list the variables you want to read from the file, for example:

DATA A; INFILE "C:\ sasfiles\testfile.csv"; INPUT VAR1 VAR2 VAR3; RUN;

DELIMITER= (DLM=)

This option enables you to tell SAS what single character is used as a delimiter in the file you are reading. Some common delimiters are comma (,), vertical pipe (|), semi-colon (;), and tab. At this time the TAB needs to be by its hexadecimal value. For the ASCII systems (UNIX, Windows, and Linux), the value is 09. For EBCDIC systems (z/OS and MVS), the value is 05. The syntax looks like this for the pipe: DLM='|'. It looks like this for a TAB on ASCII systems: DLM='09'x.


data a;

infile  "d:\aaa.txt" delimiter='09'x ;

input AcquirorPERMN DateAnnounced  yymmdd10.;

format DateAnnounced  yymmdd10.;

run;


DATA toads0;

INFILE  "D:\Prof_zhang\t1999-2004.csv"  delimiter = ','  MISSOVER DSD lrecl=32767 firstobs=2;

INPUT t1 t2 t3 $ t4 $  t5 $  t6-t80;

RUN;



2.SPACE分割,第一行为变量名

PROC IMPORT OUT=A

            DATAFILE= "D:\a\word.txt"

            DBMS=DLM REPLACE;

     DELIMITER='20'x;

     GETNAMES=YES;

     DATAROW=2;

RUN;

 

PROC EXPORT DATA=A

            OUTFILE= "C:\b.txt"

            DBMS=DLM REPLACE;

     DELIMITER='20'x;

RUN;

 

二、导入导出EXCEL文件(xls格式)程序如下:

PROC IMPORT OUT=A

            DATAFILE= "F:\cc.xls"

            DBMS=EXCEL REPLACE;

     SHEET="Sheet1$";

     GETNAMES=YES;

RUN;

 

PROC EXPORT DATA=WORK.A

            OUTFILE= "D:\export1.xls"

            DBMS=EXCEL REPLACE;

     SHEET="nameofsheet";

RUN;

http://blog.sina.com.cn/s/blog_743c902a0100z6e2.html

%macro o2xl(xlname,sdata);
 ods tagsets.ExcelXP  file="d:\name.xls"  options(sheet_name="&name.") style=XLStatistical;

 proc print data=&data. noobs label;
 run;

%mend;

* style 需要另外设置, label 表示在excel输出sas标签;
ods results noresults;
ods listing close;
ods tagsets.ExcelXP file="..\file_name.xls" options(sheet_name="xlname0") style=XLStyle;
 proc print data=sdata0 noobs label;
 run;

*table 1;
 %o2xl(xlname1,sdata1);
*table 2;
 %o2xl(xlname2,sdata2);
   ……
ods tagsets.excelxp close;


单个数据表输出:

ods results noresults;
ods listing close;
ods tagsets.ExcelXP file="d:\file_name.xls" options(sheet_name="sheet1") style=XLStyle;

 proc print data=sdata0 noobs label;
 run;

ods tagsets.excelxp close;



三、导入导出EXCEL文件(CSV格式)程序如下:

PROC IMPORT OUT=A

            DATAFILE= "D:\export1.csv"

            DBMS=CSV REPLACE;

    GETNAMES=YES;

RUN;


 

DATA music;

INFILE ’c:\MyRawData\Bands.csv’ DLM = ’,’ DSD MISSOVER;

INPUT BandName :$30. GigDate :MMDDYY10. EightPM NinePM TenPM ElevenPM;

RUN;


PROC EXPORT DATA=A

            OUTFILE= "D:\export1.csv"

            DBMS=CSV  REPLACE;

RUN;

 

四、导入导出ACCESS文件(mdb格式)程序如下:

PROC IMPORT OUT=A

            DATATABLE= "username"

            DBMS=ACCESS REPLACE;

     DATABASE="D:\all\userinfo.mdb";

RUN;

 

PROC EXPORT DATA=A

            OUTTABLE= "export1"

            DBMS=ACCESS REPLACE;

     DATABASE="D:\example.mdb"; *must be an exsited database;

RUN;

五、导入SPSS文件(SAV格式)程序如下:

PROC IMPORT OUT=A

            DATAFILE= "d:\aa.sav"

            DBMS=SAV REPLACE;

RUN;

proc export data=A 

             outfile= "d:\l2.sav" 

             DBMS=SAV REPLACE;

run;


六、导入文件(STATA格式)程序如下:

proc import out=a 

        datafile = "d:\aaa.dta"

         REPLACE;
        run;
proc contents data=
a;
run;

 


proc export data=dd.return  outfile='D:\pro_car\return.dta';

run;


SAS导出到STATA格式:

%include "C:\Program Files\SAS\savastata.sas"; 

data result;                                       
set a;
run;

%savastata(D:\, -replace); 



 

Reading PC SAS Data Files & Formats into SPSS for Windows

  1. Under SAS, create a library defined as the output file for an export job, e.g.:
             LIBNAME SPSS XPORT 'C:\SPSS\SASXPRT1.DAT';
    
    
    which creates a SAS export file called SASXPRT1.DAT in a directory called C:\SPSS, referred to under SAS as libname SPSS. Any of these names can be changed, except for the engine type XPORT. Note that the library is associated with a DOS file, rather than a DOS directory.
  2. If you need user-defined formats to be copied with the data, associate a different libname with the XPORT engine, and copy your formats catalog to a scratch dataset (called, say, FORMTS) in the WORK directory, e.g.,
             LIBNAME FORMT XPORT 'C:\SPSS\SASFORMT.DAT';
                    PROC FORMATS LIBRARY=LIBRARY CNTLOUT=FORMTS;
    
    
  3. Use PROC COPY to put the relevant data into the empty file, e.g.,
                   PROC COPY IN=DATA OUT=SPSS; SELECT MYDSET;
    
    
    which puts dataset DATA.MYDSET into the export file. If you made a format file in step 2, then also execute the command:
             PROC COPY IN=WORK OUT=FORMT; SELECT FORMTS;
    
    
  4. Under SPSS, execute the command:
    GET SAS DATA='C:\SPSS\SASXPRT1.DAT' DSET(MYDSET)
        /FORMATS='C:\SPSS\SASFORMT.DAT' FSET(FORMTS).
    
    assuming the file name and location to be as specified in step 1; omit the /FORMATS switch if you didn't do the stuff in step 2.


现将要保存的数据集放在一个文件夹中,然后读入到临时文件,最后输出到一个EXCEL表格。sheet1/2/3...
%macro test(lib);
options noxwait;
x "del d:\test.xls";
libname dd 'd:\jjj';
data test1;
        set dd.airline;
run;
data test2;
        set dd.alcohol;
run;
data test3;
        set dd.andy;
run;

proc sql noprint;
        select count(memname) into:_nobs from sashelp.vtable where libname="%upcase(&lib)";
        select memname into:_memname separated by " " from sashelp.vtable where libname="%upcase(&lib)";
quit; 

libname test excel "d:\test.xls";

%do i=1 %to &_nobs.;
        %let tablename=%scan(&_memname.,&i.);
                data test.&tablename.;
                       set &tablename.;
                run;
%end;
libname test clear;
%mend;
%test(work);





可以使用系统内置的tagsets.excelxp来分worksheet输出 

ods  tagsets.excelxp  file="d:\test.xls" options(sheet_name="print") style=analysis;
proc print data=sashelp.class;run;

ods  tagsets.excelxp  options(sheet_name="freq");
proc freq data=sashelp.class;
     tables sex;
run;

ods tagsets.excelxp close;


SAS Learning Module

Inputting data into SAS


This module will show how to input raw data into SAS, showing how to read instream data and external raw data files using some common raw data formats.  Section 3 shows how to read external raw data files on a PC, UNIX/AIX, and Macintosh, while sections 4-6 give examples showing how to read the external raw data files on a PC, however these examples are easily converted to work on UNIX/AIX or a Macintosh based on the examples shown in section 3.


1. Reading free formatted data instream


One of the most common ways to read data into SAS is by reading the data instream in a data step - that is, by typing the data directly into the syntax of your SAS program. This approach is good for relatively small datasets. Spaces are usually used to "delimit" (or separate) free formatted data. For example:


 

DATA cars1;

 INPUT make $ model $ mpg weight price;

CARDS;

AMC Concord 22 2930 4099

AMC Pacer   17 3350 4749

AMC Spirit  22 2640 3799

Buick Century 20 3250 4816

Buick Electra 15 4080 7827

;

RUN; 

After reading in the data with a data step, it is usually a good idea to print the first few cases of your dataset to check that things were read correctly.


title "cars1 data";

PROC PRINT DATA=cars1(obs=5);

RUN; 

Here is the output produced by the proc print statement above.


cars1 data            


OBS   MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827

2. Reading fixed formatted data instream


Fixed formatted data can also be read instream. Usually, because there are no delimiters (such as spaces, commas, or tabs) to separate fixed formatted data, column definitions are required for every variable in the dataset. That is, you need to provide the beginning and ending column numbers for each variable. This also requires the data to be in the same columns for each case. For example, if we rearrange the cars data from above, we can read it as fixed formatted data:


DATA cars2;

  INPUT make $ 1-5 model $ 6-12 mpg 13-14 weight 15-18 price 19-22;

CARDS;

AMC  Concord2229304099

AMC  Pacer  1733504749

AMC  Spirit 2226403799

BuickCentury2032504816

BuickElectra1540807827

;

RUN;


TITLE "cars2 data";

PROC PRINT DATA=cars2(obs=5);

RUN; 

The benefit of fixed formatted data is that you can fit more information on a line when you do not use delimiters such as spaces or commas. 


Here is the output produced by the proc print statement above.


cars2 data            


OBS    MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827

3. Reading fixed formatted data from an external file


Suppose you are using a PC and you have a file named cars3.dat, that is stored in the c:\carsdata directory of your computer.  Here's what the data in the file cars3.dat look like:


AMC  Concord2229304099

AMC  Pacer  1733504749

AMC  Spirit 2226403799

BuickCentury2032504816

BuickElectra1540807827 

To read the file cars3.dat, use the following syntax.


 DATA cars3;

  INFILE "c:\carsdata\cars3.dat";

  INPUT make $ 1-5 model $ 6-12 mpg 13-14 weight 15-18 price 19-22;

RUN;


TITLE "cars3 data";

PROC PRINT DATA=cars3(obs=5);

RUN; 

Here is the output produced by the proc print statement above.


cars3 data            


OBS    MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827

Suppose you were working on UNIX.  The UNIX version of this program, assuming the file cars3.dat is located in the directory ~/carsdata, would use the syntax shown below.  (Note that the "~" in the UNIX pathname above refers to the user's HOME directory. Hence, the directory called carsdata that is located in the users HOME directory.)


DATA cars3;

  INFILE "~/carsdata/cars3.dat";

  INPUT make $ 1-5 model $ 6-12 mpg 13-14 weight 15-18 price 19-22;

RUN;


TITLE "cars3 data";

PROC PRINT DATA=cars3(obs=5);

RUN; 

Likewise, suppose you were working on a Macintosh.  The Macintosh version of this program, assuming cars3.dat is located on your hard drive (called Hard Drive) in a folder called carsdata would look like this.


DATA cars3;

  INFILE 'Hard Drive:carsdata:cars3.dat';

  INPUT make $ 1-5 model $ 6-12 mpg 13-14 weight 15-18 price 19-22;

RUN;


TITLE "cars3 data";

PROC PRINT DATA=cars3(OBS=5);

RUN; 

In examples 4, 5 and 6 below, you can change the infile statement as these examples have shown to make the programs appropriate for UNIX or for the Macintosh.


4. Reading free formatted (space delimited) data from an external file


Free formatted data that is space delimited can also be read from an external file. For example, suppose you have a space delimited file named cars4.dat, that is stored in the c:\carsdata directory of your computer. 


Here's what the data in the file cars4.dat look like:


AMC Concord 22 2930 4099

AMC Pacer   17 3350 4749

AMC Spirit  22 2640 3799

Buick Century 20 3250 4816

Buick Electra 15 4080 7827 

To read the data from cars4.dat into SAS, use the following syntax:


DATA cars4;

  INFILE "c:\carsdata\cars4.dat";

  INPUT make $ model $ mpg weight price;

RUN;


TITLE "cars4 data";

PROC PRINT DATA=cars4(OBS=5);

RUN; 

Here is the output produced by the proc print statement above.


cars4 data            


OBS    MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827 

5. Reading free formatted (comma delimited) data from an external file


Free formatted data that is comma delimited can also be read from an external file. For example, suppose you have a comma delimited file named cars5.dat, that is stored in the c:\carsdata directory of your computer. 


Here's what the data in the file cars5.dat look like:


AMC,Concord,22,2930,4099

AMC,Pacer,17,3350,4749

AMC,Spirit,22,2640,3799

Buick,Century,20,3250,4816

Buick,Electra,15,4080,7827 

To read the data from cars5.dat into SAS, use the following syntax:


DATA cars5;

  INFILE "c:\carsdata\cars5.dat" delimiter=',';

  INPUT make $ model $ mpg weight price;

RUN;


TITLE "cars5 data";

PROC PRINT DATA=cars5(OBS=5);

RUN; 

Here is the output produced by the proc print statement above.


cars5 data            


OBS    MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827 

6. Reading free formatted (tab delimited) data from an external file


Free formatted data that is TAB delimited can also be read from an external file. For example, suppose you have a tab delimited file named cars6.dat, that is stored in the c:\carsdata directory of your computer. 


Here's what the data in the file cars6.dat look like:


AMC Concord 22 2930 4099

AMC Pacer 17 3350 4749

AMC Spirit 22 2640 3799

Buick Century 20 3250 4816

Buick Electra 15 4080 7827 

To read the data from cars6.dat into SAS, use the following syntax:


DATA cars6;

  INFILE "c:\carsdata\cars6.dat" DELIMITER='09'x;

  INPUT make $ model $ mpg weight price;

RUN;


TITLE "cars6 data";

PROC PRINT DATA=cars6(OBS=5);

RUN; 

Here is the output produced by the proc print statement above.


cars6 data            


OBS    MAKE      MODEL     MPG    WEIGHT    PRICE

1     AMC      Concord     22     2930      4099

2     AMC      Pacer       17     3350      4749

3     AMC      Spirit      22     2640      3799

4     Buick    Century     20     3250      4816

5     Buick    Electra     15     4080      7827

7. Problems to look out for


If you read a file that is wider than 80 columns, you may need to use the lrecl= parameter on the infile statement.

8. For more information


For more detailed information on reading raw data into SAS, see Reading data into SAS in the SAS Library.

To learn how to create permanent SAS system files, see the SAS Learning Module on Reading and writing SAS system files.

 

For information on creating and recoding variables once you have entered your data, see the SAS Learning Module on Creating and recoding variables.



Section 2.4

First program

* Read internal data into SAS data set uspresidents; 

DATA uspresidents;    

INPUT President $ Party $ Number;

   DATALINES;

Adams     F  2

Lincoln   R 16

Grant     R 18

Kennedy   D 35

   ;

RUN;

Second program

* Read data from external file into SAS data set; 

DATA uspresidents;

   INFILE 'c:\MyRawData\President.dat';

   INPUT President $ Party $ Number;

RUN;

Section 2.5

 

* Create a SAS data set named toads;

* Read the data file ToadJump.dat using list input;

DATA toads;

   INFILE 'c:\MyRawData\ToadJump.dat';

   INPUT ToadName $ Weight Jump1 Jump2 Jump3;

RUN;

* Print the data to make sure the file was read correctly;

PROC PRINT DATA = toads;

   TITLE 'SAS Data Set Toads';

RUN;

Section 2.6

 

* Create a SAS data set named sales;

* Read the data file OnionRing.dat using column input;

DATA sales;

   INFILE 'c:\MyRawData\OnionRing.dat';

   INPUT VisitingTeam $ 1-20 ConcessionSales 21-24 BleacherSales 25-28

         OurHits 29-31 TheirHits 32-34 OurRuns 35-37 TheirRuns 38-40;

RUN;

* Print the data to make sure the file was read correctly;

PROC PRINT DATA = sales;

   TITLE 'SAS Data Set Sales';

RUN;

Section 2.7

 

* Create a SAS data set named contest;

* Read the file Pumpkin.dat using formatted input;

DATA contest;

   INFILE 'c:\MyRawData\Pumpkin.dat';

   INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.

         (Score1 Score2 Score3 Score4 Score5) (4.1);

RUN;

* Print the data set to make sure the file was read correctly;

PROC PRINT DATA = contest;

   TITLE 'Pumpkin Carving Contest';

RUN;

Section 2.9

First Program

 

* Create a SAS data set named nationalparks;

* Read a data file NatPark.dat mixing input styles;

DATA nationalparks;

   INFILE 'c:\MyRawData\NatPark.dat';

   INPUT ParkName $ 1-22 State $ Year @40 Acreage COMMA9.;

RUN;

PROC PRINT DATA = nationalparks;

   TITLE 'Selected National Parks';

RUN;

Second Program

* Create a SAS data set named nationalparks;

* Read a data file NatPark.dat mixing input styles;

DATA nationalparks;

   INFILE 'c:\MyRawData\NatPark.dat';

   INPUT ParkName $ 1-22 State $ Year Acreage COMMA9.;

RUN;

PROC PRINT DATA = nationalparks;

   TITLE 'Selected National Parks';

RUN;

Section 2.10

 

DATA weblogs;

  INFILE 'c:\MyWebLogs\dogweblogs.txt';

  INPUT @'[' AccessDate DATE11. @'GET' File :$20.;

RUN;

PROC PRINT DATA = weblogs;

  TITLE 'Dog Care Web Logs';

RUN;

Section 2.11

 

* Create a SAS data set named highlow;

* Read the data file using line pointers;

DATA highlow;

   INFILE 'c:\MyRawData\Temperature.dat';

   INPUT City $ State $ 

         / NormalHigh NormalLow

         #3 RecordHigh RecordLow;

RUN;

PROC PRINT DATA = highlow;

   TITLE 'High and Low Temperatures for July';

RUN;

Section 2.12

 

* Input more than one observation from each record;

DATA rainfall;

   INFILE 'c:\MyRawData\Precipitation.dat';

   INPUT City $ State $ NormalRain MeanDaysRain @@;

RUN;

PROC PRINT DATA = rainfall;

   TITLE 'Normal Total Precipitation and';

   TITLE2 'Mean Days with Precipitation for July';

RUN;

Section 2.13

 

* Use a trailing @, then delete surface streets;

DATA freeways;

   INFILE 'c:\MyRawData\Traffic.dat';

   INPUT Type $ @;

   IF Type = 'surface' THEN DELETE;

   INPUT Name $ 9-38 AMTraffic PMTraffic;

RUN;

PROC PRINT DATA = freeways;

   TITLE 'Traffic for Freeways';

RUN;

Section 2.14

First Program

DATA icecream;

   INFILE 'c:\MyRawData\IceCreamSales.dat' FIRSTOBS = 3;

   INPUT Flavor $ 1-9 Location BoxesSold;

RUN;

 Second Program 

DATA icecream;

   INFILE 'c:\MyRawData\IceCreamSales2.dat' FIRSTOBS = 3 OBS=5;

   INPUT Flavor $ 1-9 Location BoxesSold;

RUN;


 Third Program 

DATA class102;

   INFILE 'c:\MyRawData\AllScores.dat' MISSOVER;

   INPUT Name $ Test1 Test2 Test3 Test4 Test5;

RUN; 


 Fourth Program 

DATA homeaddress;

   INFILE 'c:\MyRawData\Address.dat' TRUNCOVER;

   INPUT Name $ 1-15 Number 16-19 Street $ 22-37;

RUN;




Section 2.15


 First Program 

DATA reading;

   INFILE 'c:\MyRawData\Books.dat' DLM = ',';

   INPUT Name $ Week1 Week2 Week3 Week4 Week5;

RUN;


 Third Program (second program intentionally omitted)

DATA music;

   INFILE 'c:\MyRawData\Bands.csv' DLM = ',' DSD MISSOVER;

   INPUT BandName :$30. GigDate :MMDDYY10. EightPM NinePM TenPM ElevenPM;

RUN;

PROC PRINT DATA = music;

   TITLE 'Customers at Each Gig';

RUN;




Section 2.16 

 

PROC IMPORT DATAFILE ='c:\MyRawData\Bands2.csv' OUT = music REPLACE;

RUN;

PROC PRINT DATA = music;    

   TITLE 'Customers at Each Gig'; RUN;




Section 2.17 

 

(data must be read from a spreadsheet) 


PROC IMPORT DATAFILE = 'c:\MyExcelFiles\OnionRing.xls' DBMS=XLS OUT = sales;

RUN;

PROC PRINT DATA = sales;

   TITLE 'SAS Data Set Read From Excel File'; RUN;




Section 2.18 


 First Program (data must be read from a spreadsheet) 

* Read an Excel spreadsheet using DDE;

FILENAME baseball DDE 'CLIPBOARD';

DATA sales;

  INFILE baseball NOTAB DLM='09'x DSD MISSOVER;

  LENGTH VisitingTeam $ 20;

  INPUT VisitingTeam CSales BSales OurHits TheirHits OurRuns TheirRuns;

RUN;


 Second Program (data must be read from a spreadsheet, must replace DDE triplet with DDE triplet for your own files

* Read an Excel spreadsheet using DDE;


OPTIONS NOXSYNC NOXWAIT;

X '"C:\MyFiles\BaseBall.xls"';

FILENAME baseball DDE 'Excel|C:\MyFiles\[BaseBall.xls]sheet1!R2C1:R5C7';

DATA sales;

  INFILE baseball NOTAB DLM='09'x DSD MISSOVER;

  LENGTH VisitingTeam $ 20;

  INPUT VisitingTeam CSales BSales OurHits TheirHits OurRuns TheirRuns;

RUN;




Section 2.19 


 First Program 

DATA distance; 

   Miles = 26.22;

   Kilometers = 1.61 * Miles;

RUN;

PROC PRINT DATA = distance;

RUN;


 Second Program 

DATA Bikes.distance; 

   Miles = 26.22;

   Kilometers = 1.61 * Miles;

RUN;

PROC PRINT DATA = Bikes.distance;

RUN;




Section 2.20 


 First Program 

LIBNAME plants 'c:\MySASLib';

DATA plants.magnolia;

   INFILE 'c:\MyRawData\Mag.dat';

   INPUT ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight

      AgeBloom Type $ Color $;

RUN;


 Second Program 

LIBNAME example 'c:\MySASLib';

PROC PRINT DATA = example.magnolia;

   TITLE 'Magnolias';

RUN;




Section 2.21


 First Program 

DATA 'c:\MySASLib\magnolia';

   INFILE 'c:\MyRawData\Mag.dat';

   INPUT ScientificName $ 1-14 CommonName $ 16-32 MaximumHeight

      AgeBloom Type $ Color $;

RUN;


 Second Program

 

PROC PRINT DATA = 'c:\MySASLib\magnolia';

   TITLE 'Magnolias';

RUN;




Section 2.22 

 

DATA funnies (LABEL = 'Comics Character Data');

   INPUT Id Name $ Height Weight DoB MMDDYY8. @@;

   LABEL Id  = 'Identification no.'

      Height = 'Height in inches'

      Weight = 'Weight in pounds'

      DoB    = 'Date of birth';

   INFORMAT DoB MMDDYY8.;

   FORMAT DoB WORDDATE18.;

   DATALINES;

53      Susie 42 41 07-11-81 

54      Charlie 46 55 10-26-54

55      Calvin 40 35 01-10-81 

56      Lucy 46 52 01-13-55

   ;

* Use PROC CONTENTS to describe data set funnies;

PROC CONTENTS DATA = funnies;

RUN;

 



0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有