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

Hello.

 

I need to sort the variables by mif, ddstl, src_ref. But then I need to output from this dataset only the first variable by mif and src_ref.

 

Can you help me?  I tried this, but not the result which I want

 

proc sort data=work.QUERY_FOR_ACTIVITY_0008 out=work.skuska;
by mif descending ddstl src_ref;
run;

data work.pokus;
set WORK.skuska;

by mif src_ref;
if first.src_ref then output;

run;

 

 

Here is table  - I want this yellow rows only:

src_ref can be more then twice in the table, but only with very similar time- difference 40sec.

Capture.JPG

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

You will need to use LAG() because you are ignoring a sorted level.  There is a possibility your expectations of when src_ref changes will be subverted, especially if src_ref 'bounces around' on a given date.

 

Example:

 

data want;
  set have;
  by mif;
if first.mif or src_ref ne lag(src_ref); run;

 

 

View solution in original post

7 REPLIES 7
ed_sas_member
Meteorite | Level 14

Hi @Laylitta 

 

There is no yellow rows 😉

Could you please update your post with the last part?

Laylitta
Calcite | Level 5
I already updated, I dont know, why it doesn´t upload - I tried it twice, but now I hope, you will see the picture.
ed_sas_member
Meteorite | Level 14

Hi @Laylitta 

 

We can see the rows now 😊

Please try this:

by mif descending src_ref;
if last.src_ref then output;

Best,

Kurt_Bremser
Super User

Why all the hassle with pictures? If you posted your data AS RECOMMENDED(!) in a data step with datalines, it only takes a copy/paste into a "little running man" window. No separate uploading necessary. And you can mark lines in the text with additional "data" that is not read.

Laylitta
Calcite | Level 5
This solution will not works for me. Because the key is ddstl. The observations are 2 together with just the differenct 40sec, but I need just one from them. If I will sort the first by src_ref, they can be e.g. 10 observations. The first two will have the date and time e.g. 5may10:15:30 and 5may 10:16:10 and the other two will have 8may10:30:40 and 8may10:31:20.
RichardDeVen
Barite | Level 11

You will need to use LAG() because you are ignoring a sorted level.  There is a possibility your expectations of when src_ref changes will be subverted, especially if src_ref 'bounces around' on a given date.

 

Example:

 

data want;
  set have;
  by mif;
if first.mif or src_ref ne lag(src_ref); run;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 628 views
  • 0 likes
  • 4 in conversation