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

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
Pyrite | Level 9
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
Pyrite | Level 9
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;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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