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

I have a very simple program that reads in the contents of all the .csv files in a Windows directory. That part of the program works fine.

 

I would like to add the file name to each record.

 

The problem I have is the variable fullfilename contains only 'C:\Users' rather than the full name. I have verified this with PUT statements.

 

In the log, SAS correctly identifies the full path and name and the proper data is imported but the ticker field (to wihich I tried to assign the parsed filename) is blank, as is the fullfilename field.

 

Thanks for your help!

 

Using Windows 10 and SAS 9.4 in Enterprise Guide

 

data ticker_files;
infile 'c:\Users\tparrent\Documents\SandP 500 Stock History\daily\table_*.csv'
    FILENAME=fullfilename
    DELIMITER=','
    FIRSTOBS=1;
put fullfilename;

do until(last);

    input dateint unknown open high low close volume;
    ticker = scan(scan(fullfilename,-1,'_'),1,'.');
    output;
end;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

make sure to specify the length as well.

 

length fullFileName sourceName $256.;

View solution in original post

4 REPLIES 4
Reeza
Super User

When you use the FILENAME you need to actually store it, I don't see that in your code, but it doesn't look complete either....

This is what you'd add and you should have a variable called sourceFile in your dataset. I don't even think fullFileName would be outputted to your dataset otherwise.

 

sourceFile = fullFileName;
tparrent
Fluorite | Level 6

I tried your sugestions and sourceFileName still contains only 'C:\Users'

 

I did post the entire code and it does run and import the data from the files

Reeza
Super User

make sure to specify the length as well.

 

length fullFileName sourceName $256.;
tparrent
Fluorite | Level 6

LENGTH fullfilename $256.; did the trick!

 

Thank you very much Reeza. I now understand something beyond the specific problem - don't get careless with variables!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 10455 views
  • 2 likes
  • 2 in conversation