DATA Step, Macro, Functions and more

Reading raw data separated by delimiter

Reply
New Contributor
Posts: 2

Reading raw data separated by delimiter

Hi All,

While going through The Little SAS Book, it is mentioned that if we are reading raw data file using list input then in case of character data there shouldn't be any embedded space.

My question here is that  this limitation is applicable only when the delimiter is blank(default delimiter,In this case we have to use option dsd to read character data with embedded space).

I am having a data set where values in raw data file are comma seperated and in character data there is embedded space. But when i am trying to read the data with the following code,it is generating correct output.

data sales;
infile 'E:\SAS data\Data\base data set\lwprg1\sales.csv' dlm = ',';
length Job_Designation $ 20;
input ID First_Name $ Last_Name $ Gender $ Salary Job_Designation $ Country $
Birth_DateSmiley Very Happyate9.
Hire_date:ddmmyy10.;
run;

Please let me know whether my understanding is correct or not and help me in clearing my confusion.

Attaching screenshot of sample raw data file(Embedded space data has been highlighted).


dataset.PNG
New Contributor
Posts: 3

Re: Reading raw data separated by delimiter

There should not be an issue with using spaces, because the comma is the delimiter.

 

Alternatively you could use proc import instead:

* Import the file;
proc import datafile = 'E:\SAS data\Data\base data set\lwprg1\sales.csv'
	out = sales
	replace;
run;

Assuming you have headers for the columns in the first row. You might need to set guessingrows.

Super User
Posts: 10,500

Re: Reading raw data separated by delimiter

However any delimited data does have a potential issue with embedded delimiter. Hence you see most applications that create commas separated files, csv, will put quotes around text with commas as part of a value (if the app doesn't do that for all character data). Which is where the SAS Infile option DSD comes into play.

 

 

 

 

Ask a Question
Discussion stats
  • 2 replies
  • 214 views
  • 1 like
  • 3 in conversation