BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
illusoryduck
Fluorite | Level 6

Hi,

 

I'm having trouble adding the filenames to a DI Studio External File. I have followed this post How to put filename into the data using SAS-DI? and In the Advanced File Parameters i have added

 

filename=_infilename;
length _infilename Filename_Used $255;
Filename_Used=_infilename;

 

But when i run the Transformation it only brings back 8 characters and the following WARNING: Length of character variable _infilename has already been set. Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of a character variable.

 

Can anyone help please?

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
illusoryduck
Fluorite | Level 6

@PatrickOne work around i have found is by ticking Override generated INFILE statement with the following statement in the Advanced file parameters tab you can move the length statement to the correct position and you wont get a warning.

 

di_infilename.png

 

i'm basically reading in the headings of multiple .csv files to make sure a certain column exists before the file is allowed to enter a flow. So if any headers are missing it will put the problem files in a check folder and carry on checking other files instead of failing.

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

@illusoryduck

I've been the author of the referenced post which had been marked as solution.

 

Looking into this again I conclude that you are right. The length statement comes too late in the sequence of events. 

 

The LENGTH statement would need to come before the INFILE statement in order for things to work. I believe there is no "hack" in DIS which would generate such code. Not sure if a User Written External File would allow for such a LENGTH statement to be ingested in the right place (before the INFILE statement).

 

I've updated the post you've referenced to be clear that this is not the solution.

 

Your subject line says Adding Multiple Filenames to DI Studio Job which is different from the problem my earlier post tried to cover.

Can you explain what you actually want to do. May be there is an easy solution to your actual problem.

illusoryduck
Fluorite | Level 6

@PatrickOne work around i have found is by ticking Override generated INFILE statement with the following statement in the Advanced file parameters tab you can move the length statement to the correct position and you wont get a warning.

 

di_infilename.png

 

i'm basically reading in the headings of multiple .csv files to make sure a certain column exists before the file is allowed to enter a flow. So if any headers are missing it will put the problem files in a check folder and carry on checking other files instead of failing.

Patrick
Opal | Level 21

@illusoryduck

Sounds like you found the DIS way how to get this done. I believe you can close this track by accepting your own contribution as solution.

 

I've never thought of doing it this way and I believe I would have gone for user writtem code (or a user transformation with a macro and prompt if used in more than one job) prior to actually reading the data via File Reader. 

...but it sounds like you found a clean way for doing things so just "carry on".

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1121 views
  • 2 likes
  • 2 in conversation