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?
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;
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
Did you try expandtabs:-
/*example*/
data have;
infile 'C:\Users\NSRINIV2\Desktop\tabandspace.txt' expandtabs truncover firstobs=2;
input a b c;
run;
Sorry for confusion. I edited the question. I want to know whether the delimiter is space or tab rather then set it.
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
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.