BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

I have sashelp.class and total 19 records .

I have to create one more record it should be empty and record number is 6.

 

1.....values

2.....values

3....values

4....values

5.....values

6....empty record

7.....values.....

......

5 REPLIES 5
novinosrin
Tourmaline | Level 20
data want;
set sashelp.class curobs=k;
output;
if k=6 then do;
call missing(of _all_);
output;
end;
run;
thanikondharish
Calcite | Level 5
May I know what is curobs
novinosrin
Tourmaline | Level 20

Basically an option for rownumber/record identifier. 

ed_sas_member
Meteorite | Level 14

Hi @thanikondharish 

 

You can also simplify your code by using the iteration number _n_ (internal variable).

NB: if you want to add a missing observation on row #6, you need to specify _n_ = 5.

It is the same for the answer proposed by @novinosrin 

 

data want;
	set sashelp.class;
	output;
	if _n_ = 5 then do;
		call missing(of _all_);
		output;
	end;
run;
novinosrin
Tourmaline | Level 20

Not a bad idea. IMHO,, use of "iteration number" in place of record number that's stated in the original objective is vulnerable to incorrect results considering the iteration number can be easily manipulated unlike precise record number. There is often that misconception among many. 

 

Right now, feeling too lazy perhaps being Friday, to demonstrate the impact but  a slight and simple WHERE/DELETE/LINK/GOTO/RETURN and more so when processing with techniques like DOW and multidim array can/probably will completely change the course of _N_ vs Record number.  One has to be very careful knowing data and objective, but with Record number, it's bullet proof!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1008 views
  • 0 likes
  • 3 in conversation