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;

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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