BookmarkSubscribeRSS Feed
Anonym432
Calcite | Level 5

What I would like to do is simply illustrated below:

 

The current data set is,

 

(line number) ID VALUE

 

(1)                  A  90

(2)                  B  90 

(3)                  C  83 

(4)                  D  49

(5)                  E  20

 

What I would like to do add a blank line between third and fourth rows like this:

(line number) ID VALUE

(1)                  A  90

(2)                  B  90 

(3)                  C  83 

(4)

(5)                  D  49

(6)                  E  20

 

I would like to know the simplest way to get the new dataset. Thanks in advance.

 

 

16 REPLIES 16
Reeza
Super User
Do you need this as a dataset or part of a final report?
Anonym432
Calcite | Level 5

At this moment, I actually need this for my final output. I would like to handle the final format in SAS as possible as I can!

 

 

Shmuel
Garnet | Level 18

what is your code to create your output ?

what are your criteria to add a blank row on output ?

 

if you use proc print - you may need add such row(s) to the input dataset.

 

if you use put statement in a data step, then you can add a blank row by:

     put ... your variables ... /;

 

if you use proc report you need define break conditions.

 

Astounding
PROC Star

Here's how to add a blank observation:

 

data want;

set have;

output;

if _n_=3;

id = ' ';

value = .;

output;

run;

 

That assumes VALUE is a numeric variable.  For printing purposes, you may want to add this option:

 

options missing=' ';

 

Otherwise, missing numerics print as a dot.  As others have implied, there may be other approaches that do a better job.  It depends on the ultimate goal.

Tom
Super User Tom
Super User

Create a new variable that you can use to indicate where to put the blank line. Perhaps a grouping variable?

 

data have;
  input id $ value ;
cards;
 A  90
 B  90
 C  83
 D  49
 E  20
;

data report;
  set have ;
  if 'A' <= ID  <= 'C' then group=1 ;
  else group=2;
run;

proc report nofs data=report headline ;
  columns group id value ;
  define group / order noprint ;
  define id / order ;
  define value / display ;
  break after group / skip ;
run;

 

 

Anonym432
Calcite | Level 5

Thank you for all your comments.

I think I gave you some confusion. What I would like to do is exaclty for my output, but I didn't mean that I would use "proc report", "proc print", etc.

 

I manually make an output using proc sql and data step. In the middle of amending the customized output format, I realized that I should have a blank between some rows, so I would like to ask you for it. 

Reeza
Super User

@Anonym432 @Astounding Solution is what your looking for then. 

 

 

You dont specify if this is missing for specific rows or a random designation. If there's a logic behind missing rows then there may be other ways. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

So what is the logical indicator that there should be a blank between 3 and 4?  I mean why not a blank between B and C?  If its just that after C you want a blank:

data want;
  set have;
  if id="C" then do;
    output;
    id="";
    output;
  end;
  else output;
run;
Shmuel
Garnet | Level 18

post your code to make it short and more efficient.

 

see my previous post: "what is your code ...:

Anonym432
Calcite | Level 5

Thanks again. I would like to add one complete empty row!

 

Another example is that, I have a data set with 10,000 rows and 5 columns (Let's say, Column1 - Column 5).

 

By addiing one empty column between two lines 3500 and 3501, I would like to change my dataset 10,001 lines with 5 columns. In this case, the empty line should be 3501th. 

 

Thanks!

 

 

Astounding
PROC Star

You can change the number of variables or the number of observations, but the tools remain the same.  Here's a version that applies to 5 variables and 10,000 observations, and adds a blank observation between the 3500th and 3501st:

 

data want;

set have;

output;

if _n_=3500;

call missing (of column1-column5);

output;

run;

 

Is this the final version of what needs to be solved?

Reeza
Super User

Not sure if this would work but what I'd try. 

 

Output;

If _n_ = 3500 then do;

Call missing(of _all_);

output;

end;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Two things I would say here:

First, using observation number (3000 or whatever) is rarely a good idea, as any amount of changes to the dataset will invalidate this programming - e.g. sort, extra rows, different processing, change to data etc.  Logical assignment should be used.

Secondly, your creating a report with 10000 observations?  That really isn't using your time to any great benefit, nobody will ever look at a report with 10000 observations in it.  What is the data, why is it not summarised?  

It makes far more sense to summarise your data, and create nice outputs based on the summaries.

chrisd9970
Fluorite | Level 6

Just found this post. This is exactly what I was looking for. However, the blank line only works in the listing output. Since I am using ODS excel to save my output into a file, the report format doesn't work. Can anyone help?

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
  • 16 replies
  • 13618 views
  • 4 likes
  • 7 in conversation