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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

View solution in original post

6 REPLIES 6
data_null__
Jade | Level 19

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
jim_toby
Quartz | Level 8

@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__
Jade | Level 19

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


 

jim_toby
Quartz | Level 8

@data_null__ thanks it worked!

Reeza
Super User

@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. 

jim_toby
Quartz | Level 8

@Reeza Thanks for the heads up, I completely missed the first file statement!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

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.

Discussion stats
  • 6 replies
  • 1228 views
  • 7 likes
  • 3 in conversation