BookmarkSubscribeRSS Feed
Wheelawake
Calcite | Level 5

Hey everyone,

I am trying to create a variable that references the input file's filename (without extension). Is there a way to do this? I am going to combine multiple test files into one excel file so I can run pivot tables for grade reports. Using the filename would be an easy way to assign the module or test name.

for example:

data work.test;

     infile 'C:\xxx.csv' dlm=',';

     Module='INSERT CODE FOR FILENAME REFERENCE HERE'

     length Student $20;

     Input Student Grade;

     format grade percent6.;

run;

proc print data=work.test;

run;

Then under the variable "Module", you would see "test 1" "test 2" "test 3" etc.

Thanks for your help!

1 REPLY 1
AdrianGriffin
Obsidian | Level 7

Add this to your infile statement ....

FILENAME=whatever

specifies a variable that SAS sets to the physical name of the currently opened input file. Like automatic variables, the FILENAME= variable is not written to the data set.

Tip:Use a LENGTH statement to make the variable length long enough to contain the value of the filename.

See:FILEVAR=

Example:Reading from Multiple Input Files



then module=whatever



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
  • 1 reply
  • 473 views
  • 1 like
  • 2 in conversation