Hello,
I'm writing code that will convert SAS to CSV and it seems like everything is working however, I want my csv which is delimited by a pipe to not start a new row with a pipe.
Example here is how my file currently looks:
|value1|value2|value3
And here is how I want it to look:
value1|value2|value3
This is my SAS Code:\
DATA _null_;
SET MySAS.SasTable; /*MySAS is the path to my SAS Table*/
FILE &outfile; /*outfile is where my csv file will be created*/
put (_all_) ('|');
RUN;
Can anyone help me resolve this issue? Thanks in advance!
You should add the DLM and DSD options to the FILE statement and not print the delimiter in the PUT statement.
6 data _null_;
7 file log dsd dlm='|';
8 set sashelp.class;
9 put (_all_)(:);
10 run;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
Carol|F|14|62.8|102.5
Henry|M|14|63.5|102.5
James|M|12|57.3|83
Jane|F|12|59.8|84.5
Janet|F|15|62.5|112.5
Jeffrey|M|13|62.5|84
You should add the DLM and DSD options to the FILE statement and not print the delimiter in the PUT statement.
6 data _null_;
7 file log dsd dlm='|';
8 set sashelp.class;
9 put (_all_)(:);
10 run;
Alfred|M|14|69|112.5
Alice|F|13|56.5|84
Barbara|F|13|65.3|98
Carol|F|14|62.8|102.5
Henry|M|14|63.5|102.5
James|M|12|57.3|83
Jane|F|12|59.8|84.5
Janet|F|15|62.5|112.5
Jeffrey|M|13|62.5|84
@data_null__ so here is what I have based on your code:
DATA _null_;
file log dsd dlm= '|';
SET MySAS.SasTable; /*MySAS is the path to my SAS Table*/
FILE &outfile; /*outfile is where my csv file will be created*/
put (_all_) (:);
RUN;
And all it seems to be doing is putting black spaces between each record. So the delimiter never even shows up
You need to put the DLM and DSD options on your FILE &OUTFILE file statement. My program is an example not a template.
@jim_toby wrote:
@data_null__ so here is what I have based on your code:
DATA _null_; file log dsd dlm= '|'; SET MySAS.SasTable; /*MySAS is the path to my SAS Table*/ FILE &outfile; /*outfile is where my csv file will be created*/ put (_all_) (:); RUN;
And all it seems to be doing is putting black spaces between each record. So the delimiter never even shows up
@data_null__ thanks it worked!
@jim_toby You have two file statements and that usually results in the last one being used, so the options from the first FILE statement are ignored. Make sure you only have one.
@Reeza Thanks for the heads up, I completely missed the first file statement!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.