BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

Hello friends

I want to ask please what is the best way to  retrieve one row before end.

For example:

I want to retrieve the row with mon=1901 (because it is one row before the end)

Data tbl1;
informat start date9. end date9.;
format start date9. end date9.;
input mon start end;
cards;
1812 '21DEC2018'd '21Jan2019'd
1901 '22Jan2019'd '21Feb2019'd
1902 '22Feb2019'd '21Mar2019'd
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ronein
Onyx | Level 15

I found the solution

Data tbl1;
informat start date9. end date9.;
format start date9. end date9.;
input mon start end;
cards;
1812 '21DEC2018'd '21Jan2019'd
1901 '22Jan2019'd '21Feb2019'd
1902 '22Feb2019'd '21Mar2019'd
;
run;



data tbl2;
set tbl1 nobs=nobs;
if _n_ =nobs-1 then keep=1;
if keep ne 1 then delete;
run;

View solution in original post

2 REPLIES 2
Ronein
Onyx | Level 15

I found the solution

Data tbl1;
informat start date9. end date9.;
format start date9. end date9.;
input mon start end;
cards;
1812 '21DEC2018'd '21Jan2019'd
1901 '22Jan2019'd '21Feb2019'd
1902 '22Feb2019'd '21Mar2019'd
;
run;



data tbl2;
set tbl1 nobs=nobs;
if _n_ =nobs-1 then keep=1;
if keep ne 1 then delete;
run;
PGStats
Opal | Level 21

Like this, you read only one record of the set:

 

data junk;
point = max(1, nobs - 1);
set sashelp.class point=point nobs=nobs;
output; stop;
run;

 

PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1077 views
  • 6 likes
  • 2 in conversation