Hello,
My colleagues here use a standardized way to name external files.
Name of the provider of the file, '-', Name of the file. file extension.
Ex: Hydro_One-Billing_Services.xml So Hydro_One is the source Billing_Services is the filename and .xml is the filename extension.
The complete (desired name) is Hydro_One-Billing_Services.xml
I tried to explain to them that SAS do not take a hyphen but they want to keep their way of doing things. Can we rename the file programmatically according to their standard?
Anything that is supported by the operating system can be used in a physical filename. Hyphens cause problems only where valid SAS names are needed (file references, libnames, datasets, variables).
Keep in mind that physical filenames are just strings to SAS.
Hydro_One-Billing_Services.xml
is perfectly valid as a filename in UNIX and Windows.
But you'll get problems with a file named
my try on a dumb & improper "filename'? .xml
😉
I don't think SAS has any trouble using a hyphen in a filename, but it would depend on what operating system your SAS process is running on whether the operating system had any issue with a hyphen in the filename.
In data step code you might do something like:
data want ;
set have;
length filename $200 ;
filename=cats(provider,'-',filetype,'.xml');
run;
In macro code you might do something like:
%let provider=Hydro_One ;
%let filetype=Billing_Services;
%let filename=&provider.-&filetype..xml;
SAS accepts the hyphen. There is no problem? It is recommended to not use special characters, spaces and such like in paths or filenames of course.
A hyphen is only an issue with a SAS data set name and even then, if you need to get around it you can use the VALIDVARNAME option ANY to set it to take a hyphen. But then you have to refer to every variable using the name literal convention:
'name-with hyphen and space'n
@alepage wrote:
I tried to explain to them that SAS do not take a hyphen but they want to keep their way of doing things. Can we rename the file programmatically according to their standard?
Anything that is supported by the operating system can be used in a physical filename. Hyphens cause problems only where valid SAS names are needed (file references, libnames, datasets, variables).
Keep in mind that physical filenames are just strings to SAS.
Hydro_One-Billing_Services.xml
is perfectly valid as a filename in UNIX and Windows.
But you'll get problems with a file named
my try on a dumb & improper "filename'? .xml
😉
Hello Kurt,
I thought the name limitation applied to any SAS Code (program) that we would like to execute.
Thank you for the details. Now, it's clearer to me.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.