BookmarkSubscribeRSS Feed
Yennie
Calcite | Level 5
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
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
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]
Yennie
Calcite | Level 5
Hi Cynthia,

That really helps lots!

Many many thanks!! 🙂 🙂

Cheers,
Yennie
Stewartli
Fluorite | Level 6

Hi Cynthia, 

I use SAS Enterprise Miner. SAS Enterprise Miner automatically added 2 empty rows to my dataset after imported dataset. I am not sure why it did that. Is there any method I can remove those rows? Thank you for your help. 

Regards, 

Stewart

 

darrylovia
Quartz | Level 8
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
s_lassen
Meteorite | Level 14

The fastest and easiest way to do it is probably to modify the dataset in place:

data x;
  if 0 then modify x; /* modify, but do not read any rows */
  output;
  output;
stop; run;
Stewartli
Fluorite | Level 6
Thank you Iassen. Appreciate it.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 14392 views
  • 1 like
  • 6 in conversation