DATA Step, Macro, Functions and more

How to distinguish space with TAB in raw data?

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

How to distinguish space with TAB in raw data?

[ Edited ]

In data step, I have to check whether the delimiter is space or tab. When I open the file with notepad. It can't distinguish space and TAB.

My question is "How to distinguish space with TAB in raw data?"

I use spread sheet to open it first then identify the delimiter. Is there any way to examine it? 


Accepted Solutions
Solution
‎09-10-2017 04:43 PM
Super User
Super User
Posts: 7,847

Re: How to distinguish space with TAB in raw data?

Posted in reply to sas_newbie3

Just look for tab characters in the file.

data _null_;
  infile 'myfile.txt' obs=1;
  input ;
  if index(_infile_,'09'x) then put 'There are tabs in this file';
run;

View solution in original post


All Replies
Regular Contributor
Posts: 150

Re: How to distinguish space with TAB in raw data?

Posted in reply to sas_newbie3

I use an advanced editor such as UltraEdit to see them. You can also do the same inNotepad++ or use Word and show control characters. 

 

HTH

PROC Star
Posts: 1,301

Re: How to distinguish space with TAB in raw data?

Did you try expandtabs:-

/*example*/

 

data have;
infile 'C:\Users\NSRINIV2\Desktop\tabandspace.txt' expandtabs truncover firstobs=2;
input a b c;
run;

Contributor
Posts: 28

Re: How to distinguish space with TAB in raw data?

Posted in reply to novinosrin

Sorry for confusion. I edited the question. I want to know whether the delimiter is space or tab rather then set it.

PROC Star
Posts: 1,301

Re: How to distinguish space with TAB in raw data?

[ Edited ]
Posted in reply to sas_newbie3

Ok, To check whether a value is delimited with space or tab, the only way that I can think of is(in a datastep) to logically check how may bytes of space the input pointer moved from the end of one value to another. So, you could use col= option to read where the input pointer is once a value is read and the where the new value begins.

 

Next, you take the difference. I suppose a tab must have a constant number of bytes that is consistent globally. So if the difference matches that constant, you take that as tab demilited 

Super User
Posts: 9,560

Re: How to distinguish space with TAB in raw data?

[ Edited ]
Posted in reply to sas_newbie3

The tab character can be noted in SAS as '09'x. You could run a preliminary data step that checks for the presence of that character, and sets it as a macro variable which can be used as the delimiter in the main input data step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎09-10-2017 04:43 PM
Super User
Super User
Posts: 7,847

Re: How to distinguish space with TAB in raw data?

Posted in reply to sas_newbie3

Just look for tab characters in the file.

data _null_;
  infile 'myfile.txt' obs=1;
  input ;
  if index(_infile_,'09'x) then put 'There are tabs in this file';
run;
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 231 views
  • 5 likes
  • 5 in conversation