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.
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;
Hi @Laylitta
We can see the rows now 😊
Please try this:
by mif descending src_ref;
if last.src_ref then output;
Best,
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.
Change the BY statement in the sort to this:
by mif src_ref descending ddstl;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.