DATA Step, Macro, Functions and more

SAS CSV File error and file names

Reply
Contributor
Posts: 30

SAS CSV File error and file names

Hi,

            i am reading multiple SAS Files assuming headers are on first row. i use firstobs=2 and there are no issues with files having headers on first row. but when headers span on row 2 and/or row 3 then i get error in log saying invalid data and has _error_= 1 and _n_=1 variable which is expected BUT is there a way to capture csv files names and count of those csv files  IN macro variable when this error is triggered. i want to display custom message something like

 

"There are 2 files with incorrect headers and names of files are A.csv, B.csv. Please update file and rerun."

 

 

 

 

Super User
Super User
Posts: 7,932

Re: SAS CSV File error and file names

Posted in reply to sasuser101

Probably. Please explain in more detail what exactly you are currently doing.   preferable with code that we can run to test.

Super User
Posts: 13,304

Re: SAS CSV File error and file names

Posted in reply to sasuser101

Assuming, since no code was included, that your FIRSTOBS=2 is on a INFILE statement you might try adding a FILENAME= option to the infile statement which would add a temporary variable similar to _n_ you could reference

 

data want;

   infile "path/name" dlm=',' firstobs=2 filename=myinfile;

   input <varlist>;

   if _error_=1 and _n_=1 then call symputx('possbadfile',myinfile);

run;

 

It would be up to you to provide additional logic for using that &possbadfile macro variable to make that message string.

 

Maybe. guessing because code would give a much better starting point.

Super User
Posts: 23,262

Re: SAS CSV File error and file names

Posted in reply to sasuser101

Why a macro variable?

 

I think you need to explain more. There are ways to handle data with multiple headers.

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 84 views
  • 0 likes
  • 4 in conversation