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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

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

2 REPLIES 2
Scott_Mitchell
Quartz | Level 8

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;

Fugue
Quartz | Level 8

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

;

;;;;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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