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
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;
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;
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
;
;;;;
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.
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.