Help using Base SAS procedures

SAS error

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

SAS error

Hi All,

I am using the code:

data test;

infile datalines dlm = ' ';

input A : 1.

        B : &11.

        C : comma20.

;

datalines;

1 NEW DELHI 1,234,567

2 LOS ANGELES 2,345,679

3 BOSTON 4,567,213

;

run;

But the values are not read properly. I would like the output to be

A        B                    C

1  NEW DELHI       1,234,567

2  LOS ANGELES   2,345,679

3  BOSTON            4,567,213

Kind Regards

SK


Accepted Solutions
Solution
‎08-13-2013 12:17 AM
Super Contributor
Posts: 297

Re: SAS error

Posted in reply to Siddharth123

Firstly you need to change your & in &11. to a $ symbol to denote a character variable.

Secondly you are using a space as a delimiter, yet your character data contains spaces.

Is this a real example of importing a text file or are you just coming to grips with using the datalines statement?

If you are just playing around with datalines then you can enclose your character variable in quotation marks and use the DSD option in your infile statement.  The DSD option ignores delimiters within the quoted string.

DATA WANT;

INFILE DATALINES DLM = ' ' DSD;

INPUT A : 8.

      B : $11.

      C : COMMA20.

;

DATALINES;

1 "NEW DELHI" 1,234,567

2 "LOS ANGELES" 2,345,679

3 "BOSTON" 4,567,213

;

RUN;

View solution in original post


All Replies
Solution
‎08-13-2013 12:17 AM
Super Contributor
Posts: 297

Re: SAS error

Posted in reply to Siddharth123

Firstly you need to change your & in &11. to a $ symbol to denote a character variable.

Secondly you are using a space as a delimiter, yet your character data contains spaces.

Is this a real example of importing a text file or are you just coming to grips with using the datalines statement?

If you are just playing around with datalines then you can enclose your character variable in quotation marks and use the DSD option in your infile statement.  The DSD option ignores delimiters within the quoted string.

DATA WANT;

INFILE DATALINES DLM = ' ' DSD;

INPUT A : 8.

      B : $11.

      C : COMMA20.

;

DATALINES;

1 "NEW DELHI" 1,234,567

2 "LOS ANGELES" 2,345,679

3 "BOSTON" 4,567,213

;

RUN;

Super Contributor
Posts: 307

Re: SAS error

Posted in reply to Siddharth123

Try this. Make sure you use double spaces between B and C data.

data test;

input A

     B & $15.

     C comma20.;

datalines;

1 NEW DELHI  1,234,567

2 LOS ANGELES  2,345,679

3 BOSTON  4,567,213

;

;;;;

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 179 views
  • 5 likes
  • 3 in conversation