If all you wanted was the new variable name to contain the filename, the new variable could be any format, not just STRING. Just change instances of the STRING command to the NUMERIC command.
For example:
begin program python3.
import os, spss
original="/Users/rick/DATA/languages/English/Employee data.sav"
fileinfo=os.path.split(original)
mypath=fileinfo[0]
myfile=fileinfo[1]
clean_filename=myfile.replace(' ','_')
spss.Submit("GET FILE '" + original + "'.")
spss.Submit("NUMERIC " + clean_filename + " (F8.2).")
spss.Submit("EXECUTE.")
end program.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Mon October 25, 2021 09:45 AM
From: Art Jack
Subject: creating variable based off of file name
Morning, I'm using several files over a period of time. They have a standard naming configuration such as 'Active January 2017', Active February 2017' etc.. Is there a way to create a variable and include all or part of the file name in the variable? thanks.
------------------------------
Art Jack
------------------------------
#SPSSStatistics