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

;

;;;;

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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