BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_newbie3
Obsidian | Level 7

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

6 REPLIES 6
AlanC
Barite | Level 11

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

https://github.com/savian-net
novinosrin
Tourmaline | Level 20

Did you try expandtabs:-

/*example*/

 

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

sas_newbie3
Obsidian | Level 7

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

novinosrin
Tourmaline | Level 20

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 

Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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