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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.