BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

Im fairly new to SAS and learning it, I have a dataset like,

obs ID start_dt end_dt

1 9000010130143072000000 20070801 20070831
2 9000010130143072000000 20070901 20070930
3 9000010130143072000000 20071001 20071031
4 9000010130143072000000 20071101 20071130
5 9000010130143072000000 20071201 20071231
6 9000010130143072000000 20080101 20080131
7 9000010130143072000000 20080201 20080229
8 9000010130143072000000 20080301 20080331
9 9000010130143072000000 20080401 20080430
10 9000010130143072000000 20080501 20080531



How can I convert it in a single record as below,

obs ID start_dt end_dt

1 9000010130143072000000 20070801 20080531


Thanks,
3 REPLIES 3
Phrzby_Phil
Calcite | Level 5
Your newness to SAS is not the main issue here. You need to specify what rule you want followed to collapse the nine obs you have shown to just one.

I'll guess it is: for all obs with same ID, create one rec with first rec's start_dt and last rec's end_dt.

Correct?

Before you answer, note I did not say "first rec" by date or by current order in the data - I did not say either. You must include this and every other imaginable detail in your specs.
Ksharp
Super User
Are these data the whole content of your dataset?
If it is, it is much achieved.
[pre]
data op;
set yourdataset end=last;
retain _start _obs ;
if _n_ eq 1 then do; _start=start_dt; _obs=obs;end;
if last then do; _end=end_dt; output; end;
keep _obs id _start _end;
run;
[/pre]


If you have a couple of groups of id ,then using 'first.id' 'last.id' to get it.

It somewhat looks like the previous post in this forum?? Weird!!

Ksharp
Peter_C
Rhodochrosite | Level 12
this is what I like about discussion forums: discovering how many different ways there might be to interpret a question ( let alone the number of ways to program the assumed answer)
Here is it min(start) and max( end) or first.start and last.end
or something else???

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
  • 3 replies
  • 747 views
  • 0 likes
  • 4 in conversation