BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
venkatnaveen
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

4 REPLIES 4
art297
Opal | Level 21

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;

venkatnaveen
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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.

art297
Opal | Level 21

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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