DATA Step, Macro, Functions and more

data is not coming correctly in datalines

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

data is not coming correctly in datalines

LIBNAME samp2 BASE "E:\Sachin\FirstRpt\Library";

data samp2.sample;
infile datalines dlm=' ' dsd ;
input country_name$ diaseases$ death ;
datalines;
India Cancer 200
India TB 300
Pakistan Cancer 200
Pakistan TB 400
united state of america TB 300
united state of america Cancer 4000
;
run;


proc print data=samp2.sample;
run;

 

 

 

Output :-

 

country_
Obs name diaseases death

1 India Cancer 200
2 India TB 300
3 Pakistan Cancer 200
4 Pakistan TB 400
5 united state .
6 united state .

 

 

How to fix this issue as data for USA is not coming correctly.


Accepted Solutions
Solution
‎03-22-2018 09:30 AM
PROC Star
Posts: 635

Re: data is not coming correctly in datalines

Hi @MG18,

 

If you have embedded blanks then use "&" modifier to read the data. Make sure that when you have embedded blanks in one variable then you have double blanks for the next variables to separate them.

 

For eg: On 1st record between India and Cancer there are two blanks.

 

data sample;
infile datalines dlm=' ' dsd ;
input country_name & $25. diaseases $ death ;
datalines;
India  Cancer 200
India  TB 300
Pakistan  Cancer 200
Pakistan  TB 400
united state of america  TB 300
united state of america  Cancer 4000
;
run;
Thanks,
Suryakiran

View solution in original post


All Replies
Valued Guide
Posts: 631

Re: data is not coming correctly in datalines

Super Contributor
Posts: 359

Re: data is not coming correctly in datalines

Hello,

 

You use space as a the delimter. Strings can thus not contain any space

or they will be interpreted as columns separators.

Use another delimiter.

Solution
‎03-22-2018 09:30 AM
PROC Star
Posts: 635

Re: data is not coming correctly in datalines

Hi @MG18,

 

If you have embedded blanks then use "&" modifier to read the data. Make sure that when you have embedded blanks in one variable then you have double blanks for the next variables to separate them.

 

For eg: On 1st record between India and Cancer there are two blanks.

 

data sample;
infile datalines dlm=' ' dsd ;
input country_name & $25. diaseases $ death ;
datalines;
India  Cancer 200
India  TB 300
Pakistan  Cancer 200
Pakistan  TB 400
united state of america  TB 300
united state of america  Cancer 4000
;
run;
Thanks,
Suryakiran
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 112 views
  • 0 likes
  • 4 in conversation