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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1045 views
  • 0 likes
  • 3 in conversation