Page 1 of 1

SAS report

PostPosted: Wed May 11, 2011 8:14 pm
by Kitz
Hi,

Please could anyone help me to create/reformat a report in SAS:

My input file has FIELD1(Max of 16 characters) FIELD2(Max 10 ) FIELD3(Max 1) with a SPACE in between each field.

My input file is something like below:
AXXXXX12345 1105111400 W
AXX34 1105101800 W
AXXXXXX123456789 1105111400 W
AXX3467 1105101500 W

Output should be of the format as below:
AXXXXX12345 1105111400 W
AXX34 1105101800 W
AXXXXXX12345678 1105111400 W
AXX3467 1105101500 W

I tried using below SAS program using SPACE delimiter; but it doesn't work properly. The reports breaks.
//SYSIN DD *
OPTIONS NOCENTER;
DATA INFILE;
INFILE UT01 DELIMITER=',';
INPUT APPL £16. IA £10. STATUS £1. ;
PROC PRINT DATA=INFILE;

DATA OFILE;
SET INFILE;
FILE UT11;
PUT @1 APPL
@20 IA
@30 STATUS
;

Please help.

Thansk & Regards,
Kitz

Re: SAS report

PostPosted: Wed May 11, 2011 8:26 pm
by Robert Sample
Since you did NOT use the Code tag, your input and output look exactly the same.

This code should do it:
DATA _NULL_;
     LENGTH APPL $ 16 IA $ 10 STATUS $ 1;
     INFILE UT01;
     INPUT APPL IA STATUS;
     FILE OUTFILE;
     PUT @01 APPL $16. @20 IA $10. @30 STATUS $1.;

Re: SAS report

PostPosted: Wed May 11, 2011 8:28 pm
by Robert Sample
I just noticed -- that should be FILE UT11; not FILE OUTFILE;

Re: SAS report

PostPosted: Wed May 11, 2011 9:35 pm
by Kitz
Vow...it worked. Thanks very much Robert.

Thanks & Regards,
Kitz

Re: SAS report

PostPosted: Wed May 11, 2011 10:40 pm
by Robert Sample
it worked
You're surprised? I've been using SAS at various work locations for well over 30 years now!

The LENGTH statement defines the variable lengths. An unformatted INPUT statement such as I used will read character data either until the first space or the length of the variable (SAS defaults to 8 bytes for character variables, which is why the LENGTH statement was needed). Numbers will be read until the first space (although SAS may do some truncation if the value exceeds normal limits for a numeric variable).

Re: SAS report

PostPosted: Thu May 12, 2011 8:03 pm
by Kitz
Thank you Robert. I tried with LENGTH but somehow it didn't work. I got it now. Well explained, thanks.

Re: SAS report

PostPosted: Thu May 12, 2011 8:07 pm
by Robert Sample
Glad to hear it helped. :)