Help using Base SAS procedures

Problem with data after exporting to txt using data step

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Problem with data after exporting to txt using data step

Hello

I have a problem - when I try to export a dataset to delimited txt file using data step export, I experience a small but annoying issue that is probably limited to this way of exporting a file because proc export does the job just fine.  Unfortunately I need to provide changes to this txt file that proc export can't do so using it is not the solution. So... the thing is - I have in my dataset columns that are always filled with some data and some that are not and in the txt file these empty cells look like this:

, ,

What I want is ,,.  How can I remove this blank space betweem delimiter?


Accepted Solutions
Solution
‎06-15-2015 06:05 AM
Respected Advisor
Posts: 3,889

Re: Problem with data after exporting to txt using data step

I believe you're looking for "DSD".

ods _all_ close;

ods listing;

options missing='';

data _null_;

  set sashelp.class;

  file print delimiter=',' DSD;

  if _n_=2 then call missing(Sex,Age,Name);

  put Height Sex Age Name Weight;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,889

Re: Problem with data after exporting to txt using data step

It would really help if you would post your code - especially the bit where you're actually writing to the text file.

So just purely guessing here:

You might be looking for something like PUT VAR1 +(-1) ',' VAR2 .....;

Occasional Contributor
Posts: 5

Re: Problem with data after exporting to txt using data step

My code:

data _null_ ;         

    set WORK.Files;

    file  outfile delimiter=','; 

if _n_ = 1 then do;

PUT 'A,B,C,D';

end;

PUT A B C D;

run ;

The output is:

A~B~C~D

F1,235, ,

What I want is:

A~B~C~D

F1,235,,,

Solution
‎06-15-2015 06:05 AM
Respected Advisor
Posts: 3,889

Re: Problem with data after exporting to txt using data step

I believe you're looking for "DSD".

ods _all_ close;

ods listing;

options missing='';

data _null_;

  set sashelp.class;

  file print delimiter=',' DSD;

  if _n_=2 then call missing(Sex,Age,Name);

  put Height Sex Age Name Weight;

run;

Occasional Contributor
Posts: 5

Re: Problem with data after exporting to txt using data step

That's it! Thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 561 views
  • 0 likes
  • 2 in conversation