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
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;
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
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;
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.
Why do you nerd blank rows? This is a display issue, so maybe you can add the spaces using PROC REPORT.
Why do you nerd blank rows? This is a display issue, so maybe you can add the spaces using PROC REPORT.
data class;
if _n_=1 then output;
set sashelp.class;
output;
run;
Thanks to all of you for your suggestions.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.