BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonatan_velarde
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

 

View solution in original post

8 REPLIES 8
Reeza
Super User

PROC REPORT can do that for reports that are printed, I'm assuming it's not a data set you want?

 

https://communities.sas.com/t5/ODS-and-Base-Reporting/Adding-a-Blank-Line-in-Proc-Report-Output/td-p...

 

 

jonatan_velarde
Lapis Lazuli | Level 10
Nice option, already saw this one, but my doubt was how to add the "#n" before and after each ID
Reeza
Super User

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;


novinosrin
Tourmaline | Level 20
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;
Reeza
Super User

@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. 

jonatan_velarde
Lapis Lazuli | Level 10
Is a nice options and very usefull, but is missing the "#n" after and before ID.
novinosrin
Tourmaline | Level 20

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;

 

jonatan_velarde
Lapis Lazuli | Level 10
Awesome!!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 4479 views
  • 3 likes
  • 3 in conversation