BookmarkSubscribeRSS Feed
Nimish28
Calcite | Level 5
Hi All,
I hope you all are safe and healthy in these tough situations.

I am working on a task where i have to import a series of files (for ex- A1-A12) .
Now the issue with importing these series of files is , I only want to import files that are comma separated and not tab delimited in this series and i am not sure how to do that because those tab delimited files fall under the series.

Need help on this.

Thank you in advance
4 REPLIES 4
Patrick
Opal | Level 21

Based on the very thin information you share:

Using a data step you could check in the first line of your data if there is a tab and only proceed with the import if there isn't one.

 

Nimish28
Calcite | Level 5
Hi Patrick,

I am using a datastep only and the importing text files from the desired folder.
Infile "path/*.txt "is the path i am using to get all the txt files from the folder but in between these txt files two txt files are tab delimited and i need to skip them while importing and i would really appreciate if you can explain how are you expecting me check the first line to filter out the files.

Thanks
ballardw
Super User

In a data step it is easy to see if first record contains commas or tabs.

 

data chartest;
   infile "your file goes here" obs=1 ;
   input;
   if index(_infile_,"09"X)>0 then <do something when tab is found>;
;

Without see a lot more of your code, such as how you are getting the file names or reading the data I can't provide a lot of details of what the "do something" should be. A very likely option would be the STOP statement to end the execution.

 

Tom
Super User Tom
Super User

Your problem description is missing a lot of pertinent issues.

So let's assume that you want to run a single data step that reads all of the files using a wildcard in the INFILE statement.

So first make sure you know how to tell which file you are reading (and so when you change files).

When starting a new file check if the it is one you want to read or skip.

data want;
  length fname $256 ;
  infile "myfiles*.txt" filename=fname truncover dsd ;
  input @;
  if fname ne lag(fname) then do;
    if indexc(_infile_,'09'x) then skip=1;
    else skip=0;
  end;
  if not skip then do;
    input .... ;
    output;
  end;
run;

If the issue is that the data is same but sometimes they use tab and sometimes they use comma then you can just modify the value used by the DLM option of the infile statement.

data want;
  length dlm $1 ;
  infile "myfiles*.txt" truncover dsd dlm=dlm;
  input @;
  if indexc(_infile_,'09'x) then dlm='09'x;
  else dlm=',';
  input .... ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 712 views
  • 1 like
  • 4 in conversation