The SAS Output Delivery System and reporting techniques

Removing blank space

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Removing blank space

I am creating CSV file from sas dataset using following code

Data _null_;
set dataset;
File "filename" DLM=',';
if _n_ eq 1 then do
****
****
Put 'A,B,C';
End;
PUt A B C;
run;

Problem is that a blank space is introduced in fileds with null values.

Please help how to avoid that.

Accepted Solutions
Solution
‎05-29-2018 01:10 AM
Super User
Super User
Posts: 8,273

Re: Removing blank space

That is what the DSD option on the FILE statement if for.

data have ;
  input a b c ;
cards;
1 2 3
4 . 6
. . 7
;
data _null_;
  set have;
  file log dsd dlm=',';
  put a b c;
run;

Results

1,2,3
4,,6
,,7

 

View solution in original post


All Replies
PROC Star
Posts: 629

Re: Removing blank space

Please provider some sample data and the full code your using or use sample SAS datasets as below. It's something to do with your data or code you have. 

 

Filename out_CSV "\Output\out_file.csv";
Data _null_;
set sashelp.class;
File out_CSV DLM=',';
PUT Name Age Sex Height Weight;
run;

 

Thanks,
Suryakiran
Occasional Contributor
Posts: 8

Re: Removing blank space

Surya ,
I am the same code and the data set is like
Column Ais Bank_code
B is PAN_Number
C is party_name
Here The problem is that some of the pan numbers are missing where where blank space is getting populated instead of null
PROC Star
Posts: 629

Re: Removing blank space

[ Edited ]

Instead of writing individual variables, create a string with like delimited and write that string to file.

 

data have;
set sashelp.class;
If sex="M" then call missing(Sex);
run;
Filename out_CSV "\Output\out_file.csv";
Data _NULL_;
set Have;
File out_CSV DLM=',';
out_Line=CATS(Name,",",Sex,",",Age,",",Height,",",Weight);
PUT out_Line;
run;
Thanks,
Suryakiran
Super User
Posts: 6,928

Re: Removing blank space

Get rid of the delimiter, and code it yourself:

 

Data _null_;
set dataset;
File "filename" noprint;
if _n_ eq 1 then do
****
****
Put 'A,B,C';
End;
PUt A +(-1) ','  B +(-1) ','  C;
run;

 

However, this method runs into trouble when A or B has a format associated with it.

Solution
‎05-29-2018 01:10 AM
Super User
Super User
Posts: 8,273

Re: Removing blank space

That is what the DSD option on the FILE statement if for.

data have ;
  input a b c ;
cards;
1 2 3
4 . 6
. . 7
;
data _null_;
  set have;
  file log dsd dlm=',';
  put a b c;
run;

Results

1,2,3
4,,6
,,7

 

Occasional Contributor
Posts: 8

Re: Removing blank space

Bingo..it worked wonders....thanks
Super User
Posts: 23,992

Re: Removing blank space

If there's nothing particularly special about your export, any reason to not use PROC EXPORT?

 

proc export data=sashelp.class outfile=filename dbms=csv replace;run;

@FLINT wrote:
I am creating CSV file from sas dataset using following code

Data _null_;
set dataset;
File "filename" DLM=',';
if _n_ eq 1 then do
****
****
Put 'A,B,C';
End;
PUt A B C;
run;

Problem is that a blank space is introduced in fileds with null values.

Please help how to avoid that.

 

Occasional Contributor
Posts: 8

Re: Removing blank space

@Reeza I m not using export cause I have to use macro variable in the header of the CSV file
☑ This topic is solved.

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

Discussion stats
  • 8 replies
  • 347 views
  • 1 like
  • 5 in conversation