Help using Base SAS procedures

How do I add two extra empty rows to my dataset?

Reply
Frequent Contributor
Posts: 78

How do I add two extra empty rows to my dataset?

hi people,

I know SAS can do this through Edit mode by adding rows to the dataset manually. However, I am writting an automated script so I need to write out the sas code to add two extra empty rows to my dataset.

Hoping someone can give me some directions!

Cheers,
Yennie
Super Contributor
Super Contributor
Posts: 3,174

Re: How do I add two extra empty rows to my dataset?

Empty rows -not sure why but you can assign a MISSING or BLANK value to all variables in the dataset and issue the OUTPUT; command. Possibly you might want to explain why you need this condition?

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,866

Re: How do I add two extra empty rows to my dataset?

Hi:
You will want to test for the end of the input file so that you only write out your two empty observations at the end. The END= option allows you to perform this test, as shown below.

cynthia
[pre]
data newclass;
** create variable to signal end of input file;
set sashelp.class end=nomore;

** output regular observations;
output;

** test for end of file. At end, NOMORE = 1;
if nomore then do;
** set variables to missing;
name = ' ';
sex = ' ';
height = .;
age = .;
weight = .;
** output 2 "empty" observations;
output;
output;
end;
run;

ods listing;
proc print data=newclass;
title '2 "empty" observations at end of file';
run;
[/pre]
Frequent Contributor
Posts: 78

Re: How do I add two extra empty rows to my dataset?

Posted in reply to Cynthia_sas
Hi Cynthia,

That really helps lots!

Many many thanks!! Smiley Happy Smiley Happy

Cheers,
Yennie
Frequent Contributor
Posts: 139

Re: How do I add two extra empty rows to my dataset?

You could also use PROC SQL to do it



proc sql;

create table shoes as
select *
from sashelp.shoes;

insert into work.shoes
set Region="";
insert into work.shoes
set Region="";
quit;

In the SET clause just pick any variable that is in your data set

D
Ask a Question
Discussion stats
  • 4 replies
  • 7462 views
  • 1 like
  • 4 in conversation