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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2236 views
  • 0 likes
  • 1 in conversation