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
;
;;;;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.