BookmarkSubscribeRSS Feed
sasuser101
Obsidian | Level 7

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."

 

 

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

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

ballardw
Super User

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.

Reeza
Super User

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...

 

 

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
  • 3 replies
  • 810 views
  • 0 likes
  • 4 in conversation