How to format date field of input file while creating a dataset in sas

时间:2016-04-15 15:20:30

标签: sas

My input file looks like this:

FCODE,AIRPORT,TDATE,CHILD,ADULT,ECAR,FCAR IA06100,CDGWE,01APR2000,8,85,3328,11730 IA05900,CDG,01APR2000,8,85,2392,8415 IA07200,FRA,01APR2000,10,97,1720,5432 IA04700,LHR,01APR2000,14,120,2576,7320

I want to read this file and create a dataset, where the TDATE file is formatted into mm/dd/yyyy. The following is my base sas code:

data test;
  infile "C:\SAS Training\testfile.txt" firstobs=2 dlm=',';
  input FCODE $  AIRPORT $ TDATE $ CHILD ADULT ECAR FCAR;
  format tdate MMDDYYYY10.;
run;

But I am getting ERROR 48-59: The informat $MMDDYY was not found or could not be loaded. Essentially I want to convert the date "01APR2000" in the input file to "04/01/2000" in the dataset.

Thanks

2 个答案:

答案 0 :(得分:0)

您需要使用正确的INFORMAT

TDATE:date。

请注意:

答案 1 :(得分:0)

请尝试以下方法。 TDATE是一个日期(SAS中的数字的特殊情况)因此在输入语句中没有跟随$。您还会在信息(SAS如何读取原始数据并将其转换)和格式(SAS如何显示数据)之间混淆。

data test;
  infile "C:\SAS Training\testfile.txt" firstobs=2 dlm=',';
  input FCODE $  AIRPORT $ TDATE CHILD ADULT ECAR FCAR;
  informat tdate DATE9.;
  format tdate DDMMYY10.;
run;