BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Guys,

 

what is the end=  options

in datastep can you give examples on this option

 

Regards,

ANAND

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

There could be many ways to use the end option, one of thing of end option is it identifies the last observation like in the example below

 

data want;
set sashelp.class end=eof;
if eof then flag=1;
run;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

There could be many ways to use the end option, one of thing of end option is it identifies the last observation like in the example below

 

data want;
set sashelp.class end=eof;
if eof then flag=1;
run;
Thanks,
Jag
BrahmanandaRao
Lapis Lazuli | Level 10

Thank u for your valuable  support 

PeterClemmensen
Tourmaline | Level 20

See the Data Step Set Statement Documentation Page and look at the END= Option

 

Also, run the code below and check the result.

 

data have;
   do x=1 to 10;
      output;
   end;
run;

data want;
   set have end=end;
   lr=end;
run;

proc print data=want;
run;
BrahmanandaRao
Lapis Lazuli | Level 10

Thank you very much 

ballardw
Super User

A little more complicated example:

data _null_;
   set work.rename end=LastName;
   if _n_ = 1 then do;
      Call execute ("Proc datasets library=&OutDataLib nodetails nolist;");
      Call execute ("modify &RenamedData;");
      Call execute ("rename ")  ;
   end;
   Call execute(catx(' ',name,' = ',newname)) ;
   if LastName then do;
      Call execute (";") ;
      Call execute ("quit;");
   end;
run;

The data set work.rename has a list of variable names that needed to be standardized so contains a Name and Newname variable.

This code creates a call to proc datasets to change the names in place with the modify statement. So we need 1) the start of proc datasets with the library and data set names (strored in macro variables) and the start of a Rename block of code, 2) all of the name to newname pairs and 3) the End option comes in to generate the end of the Rename block and the call to Proc Datasets ;

 

Sometimes the End option can be used to create a cntlin dataset for Proc Format to set the "other" value options for a format as you need a bit more than a simple list of start and label values.

 

With the Report Writing Interface for the data step the END option could be used to write what ever might appear at the bottom of any generated text.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 7015 views
  • 3 likes
  • 4 in conversation