BookmarkSubscribeRSS Feed
the_yeti
Obsidian | Level 7

Hello,

 

I'm following the steps in How to Export SAS Datasets as a .CSV File in SAS University Edition to export a CSV file from a SAS dataset, with something like this:

 

libname example "/folders/myfolders";
run;

proc export data=example.Example-Data
  outfile='/folders/myfolders/ExampleCSV.csv'
  dbms=csv
  replace;
run;

However, my input file has a dash in it e.g. the file is called `Example-Data.sas7bdat`.

 

SAS give me an error because "-" (dash) is not allowed in variable names. I'm not able to rename the file, so I need a way to tell SAS to get the file name from a string, instead of a variable name.

 

How can I do that?

5 REPLIES 5
Kurt_Bremser
Super User

Dashes are not allowed in valid SAS names. You could work around by setting

options validvarname=any;

and

data=example.'Example-Data'n

but I strongly, and I mean STRONGLY, recommend to rename the .sas7bdat file from the commandline and to work with standard SAS names.

How was the dataset created in the first place? Fix the mistake there.

the_yeti
Obsidian | Level 7

Thank you Kurt! I'll give that a try.

 

I receive CSV files from an external party / system that exists for many years (running Windows) and the files come with all sorts of file names that I cannot control (nor it is feasible to change such an old system), so I need to read them however they are named.

 

 

Kurt_Bremser
Super User

External files (like csv's) can have any name that the OS supports. SAS datasets need to adhere to valid SAS names. If you always receive data in csv format, you set the dataset names when importing.

Reeza
Super User

The name of the SAS data set has nothing to do with the name of the original csv files. I understand not changing processes, but this is known as technical debt and you need to start somewhere. At least moving forward, make sure you don't continue this practice.  

 


@the_yeti wrote:

Thank you Kurt! I'll give that a try.

 

I receive CSV files from an external party / system that exists for many years (running Windows) and the files come with all sorts of file names that I cannot control (nor it is feasible to change such an old system), so I need to read them however they are named.

 

 


 

Ksharp
Super User

filename with a dash is illegal name in sas.

1) rename it as a legal name.

2)

options  validmemname=extend ;

 

proc export data=example.'Example-Data'n

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1717 views
  • 4 likes
  • 4 in conversation