SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
sustagens
Pyrite | Level 9

I know nobs can be used but just wondering if there also exists a start option since there is an "end" one.

2 REPLIES 2
gamotte
Rhodochrosite | Level 12
Hello,

In a data step, a variable _N_ is automatically created and contains the currently processed row number. So you can just test :
if _N_=1 then ...
Kurt_Bremser
Super User

Actually, _N_ contains the number of the current data step iteration. In most cases, since you only execute a set or merge statement once per iteration, this will correspond to the row number, but if you execute these statements more than once, you will get another result.

Compare this:

data test1;
set sashelp.class;
count = _N_;
run;

with this:

data test2;
do until (end_of_file);
  set sashelp.class end=end_of_file;
  count = _N_;
  output;
end;
run;

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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