DATA Step, Macro, Functions and more

Inserting Blank Rows

Accepted Solution Solved
Reply
Regular Contributor
Posts: 183
Accepted Solution

Inserting Blank Rows

Hi Experts,

I use the following code to insert a blank row for each observation:

 

data want;
set have;
output; /* Output real observation */
if mod(_n_,1)=0;
array allnums {*} _numeric_ ;
array allchar {*} _character_ ;
drop i;
do i=1 to dim(allnums); allnums{i}=.; end;
do i=1 to dim(allchar); allchar{i}=' '; end;
output; /* Output blank observation */

run;
options missing=' '; /* Display numeric missing as blank */

 

 

My question is: How can I insert two or more blank rows for each observation?

Another question is: How can I insert a blank row in the beginning of the dataset?

 

Thanks,

Abu Chowdhury


Accepted Solutions
Solution
‎05-09-2017 07:46 AM
PROC Star
Posts: 283

Re: Inserting Blank Rows

Posted in reply to novinosrin

For example:

 

data want;

if 0 then set sashelp.class;

if _n_=1 then do;

call missing(of _all_);

output;

end;

set sashelp.class;

output;

call missing(of _all_);

output;

output;

run;                                                                      

View solution in original post


All Replies
PROC Star
Posts: 283

Re: Inserting Blank Rows

[ Edited ]
Posted in reply to AbuChowdhury

I find it incomprehensive to use if  mod(_n_,1)=0, that is anyway going to be 0 for all iteractions when the denominator is 1. 

Secondly, you could simply use call missing(of _all_) and output staments in one shot without having to declare and loop through array elements.

 

Best Regards,

Naveen Srinivaan

Solution
‎05-09-2017 07:46 AM
PROC Star
Posts: 283

Re: Inserting Blank Rows

Posted in reply to novinosrin

For example:

 

data want;

if 0 then set sashelp.class;

if _n_=1 then do;

call missing(of _all_);

output;

end;

set sashelp.class;

output;

call missing(of _all_);

output;

output;

run;                                                                      

Super User
Posts: 5,498

Re: Inserting Blank Rows

Posted in reply to novinosrin

That's a good set of tools for the job.  Notice also a simplifying possibility:

 

if 0 then set sashelp.class;

if _n_=1 then output;

 

Since the variables are already missing when _n_=1, you don't have to jump through that hoop of setting them to missing.

Super User
Posts: 19,771

Re: Inserting Blank Rows

Posted in reply to AbuChowdhury

Why do you nerd blank rows? This is a display issue, so maybe you can add the spaces using PROC REPORT. 

Super User
Posts: 19,771

Re: Inserting Blank Rows

Posted in reply to AbuChowdhury

Why do you nerd blank rows? This is a display issue, so maybe you can add the spaces using PROC REPORT. 

Super User
Posts: 10,020

Re: Inserting Blank Rows

Posted in reply to AbuChowdhury
data class;
if _n_=1 then output;
set sashelp.class;
output;
run;
Regular Contributor
Posts: 183

Re: Inserting Blank Rows

Thanks to all of you for your suggestions.

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 601 views
  • 1 like
  • 5 in conversation