Hi there:
i have this data set composed by lines and some characters, here i need to create empty lines under each two rows
data have;
input ID A$ B$ C$ D$ E$ F$ G$;
cards;
1 255 341 154 238 ? 253 134 117 116 ?
1 ? ? 154 238 ? 253 134 125 116 ?
2 255 335 154 238 101 239 134 117 116 107
2 ? ? 154 250 101 253 134 125 116 115
3 255 319 154 238 101 239 134 117 116 107
3 ? ? 154 238 109 253 134 125 116 115
;
what i need is:
#1 | |||||||||
255 | 341 | 154 | 238 | ? | 253 | 134 | 117 | 116 | ? |
? | ? | 154 | 238 | ? | 253 | 134 | 125 | 116 | ? |
#2 | |||||||||
255 | 335 | 154 | 238 | 101 | 239 | 134 | 117 | 116 | 107 |
? | ? | 154 | 250 | 101 | 253 | 134 | 125 | 116 | 115 |
#3 | |||||||||
255 | 319 | 154 | 238 | 101 | 239 | 134 | 117 | 116 | 107 |
? | ? | 154 | 238 | 109 | 253 | 134 | 125 | 116 | 115 |
Thank you very much
slight adjustement
data want;
if 0 then set have;
array t(*) a--g;
if _n_=1 then do;call missing(of t(*));A=cats('#','1');output;end;
set have;
by id;
output;
if last.id then do;call missing(of t(*));A=cats('#',id+1);output;end;
drop id;
run;
PROC REPORT can do that for reports that are printed, I'm assuming it's not a data set you want?
I'd use a Data _null_ step then with explict PUT statements which would easily do that.
@jonatan_velarde wrote:
Nice option, already saw this one, but my doubt was how to add the "#n" before and after each ID
But it's not what your question was - 'How to insert empty row under conditions' was what you asked, so that's what I answered.
proc sort data=sashelp.class out=class;
by age;
run;
data _null_;
set class;
by age;
if first.age then do;
put 'Age #' age;
end;
put name sex weight height;
run;
data have;
input ID A$ B$ C$ D$ E$ F$ G$;
cards;
1 255 341 154 238 ? 253 134 117 116 ?
1 ? ? 154 238 ? 253 134 125 116 ?
2 255 335 154 238 101 239 134 117 116 107
2 ? ? 154 250 101 253 134 125 116 115
3 255 319 154 238 101 239 134 117 116 107
3 ? ? 154 238 109 253 134 125 116 115
;
data want;
if 0 then set have;
array t(*) a--g;
if _n_=1 then do; call missing(of t(*));output;end;
set have;
by id;
output;
if last.id then do;call missing(of t(*));output;end;
run;
@novinosrin is better because it creates a data set that you can use with PROC PRINT to any ODS output, such as PDF or Excel. Mine will work for text files and such but it's more cumbersome as well.
slight adjustement
data want;
if 0 then set have;
array t(*) a--g;
if _n_=1 then do;call missing(of t(*));A=cats('#','1');output;end;
set have;
by id;
output;
if last.id then do;call missing(of t(*));A=cats('#',id+1);output;end;
drop id;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.