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.....
......
data want;
set sashelp.class curobs=k;
output;
if k=6 then do;
call missing(of _all_);
output;
end;
run;
Basically an option for rownumber/record identifier.
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.