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

Hey all! I'm quite new to SAS. I am working with a large data set that lists members with their coverage dates. So, if I were a member and I had coverage for the entire year, there are 12 rows for me with 1/1/15, 2/1/15, and so on all the way to December.

I want to show just ONE line for each member. I need it to be the last month of coverage. For most, it will be December. I was told to use "last.incmth" (incmth is the variable). I'm not having any luck, and I don't want to make this too complicated if possible. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Actually you likely want the last member ID value. A stub of code that should accomplish this is:

If the data is sorted this step isn't needed but just in case:

proc sort data=have; by memberid incmth; run;

Then to get the data you want:

Data want;

     set have;

     by memberid incmth;

     if last.membered;

run;

IF the data crosses Years and you need the last within each year you would need to add a Year value to use in the by statement: by membered year incmth;

and use last.year to get the last value for each year associated with a member.

View solution in original post

2 REPLIES 2
ballardw
Super User

Actually you likely want the last member ID value. A stub of code that should accomplish this is:

If the data is sorted this step isn't needed but just in case:

proc sort data=have; by memberid incmth; run;

Then to get the data you want:

Data want;

     set have;

     by memberid incmth;

     if last.membered;

run;

IF the data crosses Years and you need the last within each year you would need to add a Year value to use in the by statement: by membered year incmth;

and use last.year to get the last value for each year associated with a member.

emmytheduck
Calcite | Level 5

ballardw - Thank you! I actually figured it out right before you posted. I forget that I need to focus on the variable that is causing the duplicates. Thank you!

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
  • 464 views
  • 1 like
  • 2 in conversation