BookmarkSubscribeRSS Feed
deleted_user
Not applicable
My original SAS data set, DS1, has one variabel, Year.

My first code looks like this:

data DS2;
set DS1;
keep year count;
if year=1996 then count+1;
run;

The program runs and I can check that count has incremented for each year=1996.

Then I tried with this code:

data DS2;
keep year count;
set DS1 end=last;
if last then output;
run;

I expected to have DS2 with one row, and with year value equal to DS1:s last year value and the same value for count as in the first case.
But now DS2 has no observations.

What's wrong with my code?

Anne
2 REPLIES 2
deleted_user
Not applicable
Editing:

Then I tried with this code:

data DS2;
keep year count;
set DS1 end=last;
if year=1996 then count+1;
if last then output;
run;
deleted_user
Not applicable
Are you sure?

I ran this code and I get an observation at the end.

data ds1;
input year;
cards;
1995
1996
1995
1997
1996
1990
;

data DS2;
keep year count;
set DS1 end=last;
if year=1996 then count+1;
if last then output;
run;

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
  • 2719 views
  • 0 likes
  • 1 in conversation