SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

help needed with import of text file using infile

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

help needed with import of text file using infile

I tried the below code

But i am not getting the. result.I need some help.Is there  any other method.help me out please

DATA Sara2013;

INFORMAT Date YYMMDD10.  Time $5. ;

FORMAT  Date YYMMDD10. Time $5. ;

INFILE 'C:\nav\2013_Satisfaction_Survey_Sara (4).txt'

LRECL=32767 dsd  dlm='' truncover firstobs=2;

INPUT @1 Date: YYMMDD10. @12 Time : $5.

  @18 Interviewer :$4. @23 Age :$2. @26 Gender :$1. @28 Address: &$18. @48 FirstTime :$6. @52 ComeAgain :$5. WhyNot: $11.  (Sat1-Sat8)(:$3.) Comments :$50.;

;

RUN;

Attachment

Accepted Solutions
Solution
‎04-05-2015 05:18 PM
PROC Star
Posts: 7,467

Re: help needed with import of text file using infile

Posted in reply to venkatnaveen

The following worked for me:

DATA Sara2013;

  INFILE 'C:\temp\2013_Satisfaction_Survey_Sara (2).txt'

    LRECL=32767 termstr=LF truncover firstobs=2;

  informat date yymmdd10.;

  informat time $5.;

  informat interviewer $4.;

  informat age $2.;

  informat gender $1.;

  informat address $18.;

  informat FirstTime $3.;

  informat ComeAgain $3.;

  informat WhyNot $11.;

  informat Sat1-Sat7 $3.;

  informat Sat8 $2.;

  informat Comments $50.;

  FORMAT  Date YYMMDD10. Time $5. ;

  INPUT @1 Date Time 12-16

    Interviewer 18-21 Age 23-24 Gender 26-26 Address 28-46

    FirstTime 48-50 ComeAgain 52-54 WhyNot 56-66

    Sat1 68-70 Sat2 72-74 Sat3 76-78 Sat4 80-82

    Sat5 84-86 Sat6 88-90 Sat7 92-94 Sat8 96-97 Comments 98-147;

  ;

RUN;

View solution in original post


All Replies
Solution
‎04-05-2015 05:18 PM
PROC Star
Posts: 7,467

Re: help needed with import of text file using infile

Posted in reply to venkatnaveen

The following worked for me:

DATA Sara2013;

  INFILE 'C:\temp\2013_Satisfaction_Survey_Sara (2).txt'

    LRECL=32767 termstr=LF truncover firstobs=2;

  informat date yymmdd10.;

  informat time $5.;

  informat interviewer $4.;

  informat age $2.;

  informat gender $1.;

  informat address $18.;

  informat FirstTime $3.;

  informat ComeAgain $3.;

  informat WhyNot $11.;

  informat Sat1-Sat7 $3.;

  informat Sat8 $2.;

  informat Comments $50.;

  FORMAT  Date YYMMDD10. Time $5. ;

  INPUT @1 Date Time 12-16

    Interviewer 18-21 Age 23-24 Gender 26-26 Address 28-46

    FirstTime 48-50 ComeAgain 52-54 WhyNot 56-66

    Sat1 68-70 Sat2 72-74 Sat3 76-78 Sat4 80-82

    Sat5 84-86 Sat6 88-90 Sat7 92-94 Sat8 96-97 Comments 98-147;

  ;

RUN;

Frequent Contributor
Posts: 89

Re: help needed with import of text file using infile

Thanks Arthur.But,what is trmstr='lF' option and why individually writing of informat statement .cant we mention with a colon modifier :

Super User
Super User
Posts: 7,039

Re: help needed with import of text file using infile

Posted in reply to venkatnaveen

You probably need to add the TRUNCOVER option to the INFILE statement since some of the lines appear shorter than others.

Also you need to add the FIRSTOBS=2 option to get it to skip the header line in the file.

PROC Star
Posts: 7,467

Re: help needed with import of text file using infile

Posted in reply to venkatnaveen

termstr=LF is to indicate that your records end with '10'x (line feed) character, rather that the combination of a CR and a line feed.

While I don't know how common it is, I have always liked defining informats rather than specifying them in the input statement and using colons. Obviously, you could try alternative approaches, but the one I suggested appears to correctly read your file.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 472 views
  • 3 likes
  • 3 in conversation