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

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

😉

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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;

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User

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?

 


 

Kurt_Bremser
Super User

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

😉

alepage
Barite | Level 11

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.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2378 views
  • 3 likes
  • 5 in conversation