Formatted input

Reply
Contributor
Posts: 43

Formatted input

I read that formatted input can be used to read both standard and non-standard fixed field data.

Is it necessary to specify an informat to read a standard data field while using formatted input, provided, the record conatin both standard and non-standard data variables?

Super Contributor
Posts: 644

Re: Formatted input

Posted in reply to JVarghese

To some extent you can mix and match input styles in the same input statement; alternately you can terminate the input statement with @ and then introduce a second input statement to read remaining values using a different style.  I tis a good idea to format the variables at the same time

The data

ID          Date               x1        x2         x3

A123     12Dec2013     3424     4553     3443

could be read

Input     ID     $4.     Date     Date9.     x1 - x3 ;

or

Input     ID     $4.     Date     Date9.   @ ;

Input     x1 - x3 ;

Richard

Respected Advisor
Posts: 3,799

Re: Formatted input

Posted in reply to RichardinOz

RichardinOz wrote:

To some extent you can mix and match input styles in the same input statement; alternately you can terminate the input statement with @ and then introduce a second input statement to read remaining values using a different style.  I tis a good idea to format the variables at the same time

The data

ID          Date               x1        x2         x3

A123     12Dec2013     3424     4553     3443

could be read

Input     ID     $4.     Date     Date9.     x1 - x3 ;

or

Input     ID     $4.     Date     Date9.   @ ;

Input     x1 - x3 ;

Richard

Your first INPUT statement would ONLY work if there is no (zero) spaces between the A123 and 12DEC2013.  FORMATTED input does not scan the input record as does LIST input.  The input statement as written reads two fields using FORMATTED input then switches to LIST input.

To read the data as you have implied with (the data) example line you need to add the colon modifier :$4. and :date9.

Adding the : modified "says" use LIST input to read the field with the specified INFORMAT.  Same as using and INFORMAT statement or ATTRIB to define the INFORMAT and then using LIST input.  INPUT ID DATE X1-X3;

Super Contributor
Posts: 644

Re: Formatted input

Posted in reply to data_null__

Thanks

I don't have access to SAS at the moment and so it's not possible to test stuff; but it's at times like these that I have most opportunity to contribute.  Bit of a dilemma.  Hope the OP has learned something from this.

Richard

Contributor
Posts: 43

Re: Formatted input

Posted in reply to data_null__

I didn't see formatted input in his first input statement just because there is no @n or +n input pointer control . I think he tries to use list input without modifiers.

My question was whether I should use an informat eg: For x1-x3 above, should I use a w.d informat when I am using only formatted input method.ie Is it a must ?. Or can I just leave it as Input @n x1 +5 x2  +5 x3 ? Please note that x1-x3 is plain numeric data without any special character in it.

Which of the following is correct?

1.Input @n x1 4. +5 x2 4.  +5 x3 4.;

2.Input @n (x1-x3) (4.);

3.Input @n x1-x3;

Thank you.

Ask a Question
Discussion stats
  • 4 replies
  • 256 views
  • 0 likes
  • 3 in conversation