努力尝试将此txt数据集读取到SAS中

时间:2019-02-17 21:23:11

标签: sas

那是数据集。我需要一个用于ShipID,Received,Shipped,City,邮政编码的变量。我将如何去做?

这是我的第一门统计学编程语言课程,我正在努力。我的教授也没什么帮助。

ShipID  Received   Shipped   Address .   
 X8742 2018/03/14 2018/03/17 Little River, KS, 67457

还有更多的台词,我已经迷失了一个小时。

infile "/home/rossfosher0/SAS Homework/SAS Sessions/WarehouseA.txt" firstobs = 2;    
input  @2-7 ShipID $ @9-18 Received: YYYYMMDD8.  @20-28 Shipped: YYYYMMDD8. @City $;    
run;

我正在尝试为此仓库设置数据集。

3 个答案:

答案 0 :(得分:0)

data mydata;   
   input @1 shipid $  @7 received yymmdd10. @18 shipped yymmdd10.  @28 address $30.;   
   format received yymmdd10. shipped yymmdd10.;
datalines;
X8742 2018/03/14 2018/03/17 blue ridge, MA 02391
;
run;

答案 1 :(得分:0)

Assuming that all rows have values for the first three variables you could just read those using list mode input. Then read the rest of the line as the address.

data want;
  infile "..." firstobs=2 truncover;
  input shipid $ received shipped address $50. ;
  informat received shipped yymmdd.;
  format received shipped yymmdd10.;
run;

If the data is really in fixed columns then you can use column locations in your INPUT statement, but that is not compatible with using informats. So either use formatted input for the two date fields or read them as strings.

input shipid $1-7 @8 Received yymmdd10. @19 Shipped yymmdd10. Address $ 30-79 ;
format Received Shipped yymmdd10.;

答案 2 :(得分:0)

Tom和DCR都正确。我更喜欢使用 Proc import 的路由。

 proc import datafile='c:\personal\My_file.csv' 
    out=SAS_data replace;
    DELIMITER=";" ;
    getnames=yes;
    guessingrows= 32767;
 run;

这是根据读取的文件进行猜测并自动创建infile语句。 (我只是从日志中复制它,如果读取错误,则进行调整。)

如果您知道数据的结构,请遵循其他答案,但这是更入门的方法。 (imho)有关更多信息,请参见documentation