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;

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 7 replies
  • 932 views
  • 0 likes
  • 4 in conversation