BookmarkSubscribeRSS Feed
Fluorite | Level 6

I have a CAS in memory table which i want to save as a CSV file in the data source associated with the CASLIB. The tables have characters and numeric fields. I am running this code on SAS Studio in SAS Viya. Below is the code that I am using.




proc casutil;

save casdata="tablename" incaslib="caslib" outcaslib="caslib" casout="filename.csv" replace;





proc cas; /
table={name="tablename" caslib="caslib"}
name="filename.csv" caslib="caslib" replace="yes";



Now in both the cases the result is same, i.e., the file is created as a CSV the numeric fields are coming properly without enclosing of quotes. But with the character fields, the character fields that have space in them are enclosed in quotes and the character fields without any space in them are not enclosed in quotes. Some thing like shown below:




Wherein the columns int_status and block_code are character fields.


This seems like a very inconsistent behavior, or may be I am unaware of the reason.


My requirement is that the character fields should be enclosed in double quotes or at the very least none of the characters fields are enclosed in quotes. I want to achieve uniformity in how a specific type of data is written. My preference is that the characters fields should be enclosed in double quotes.


Is there is some option using which this can be achieved?

Super User Tom
Super User

Looks like a normal CSV file, other than those places with two double quote characters next to each other.


Only values that contain the delimiter character or the quote character need to have quotes around them. Whether you think they represent numbers or strings doesn't matter in whether the quotes are needed or not.

Fluorite | Level 6

Hi Tom,


Thanks for the inputs.


The Double Quotes next to each other are "spaces" in my table.


Now when you say "Only values that contain the delimiter character or the quote character need to have quotes around them" , do you mean that it takes "space" as a delimiter? Because my string does not have quotes and the delimiter for my file is "comma".

and if it considers space as a delimiter can you suggest any option which specifies that space is not a delimiter?


Many Thanks.


Super User Tom
Super User

Normal SAS considers a character variable with only spaces in it as a missing value. So I would expect that a variable that consists only of spaces would generate nothing in the CSV file as that is the normal way to represent a missing value. Perhaps CAS interprets those types of values differently?  Perhaps it supports variable length character strings?  Similarly missing numeric values should be represented by no characters in the file.


Here is a simple SAS data step to demonstrate how missing values normally appear in CSV files.

504   data test;
505    set sashelp.class (obs=3);
506    if _n_=1 then age=.;
507    if _n_=2 then sex=' ';
508    file log dsd ;
509    put (_all_) (+0);
510   run;

NOTE: There were 3 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 3 observations and 5 variables.


SAS Employee

That is normal and you can't change it.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


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
  • 4 replies
  • 3 in conversation