data qc2;
input cm13 key_str key_expire feed_key first_use last_use;
cards;
3710100000000 102158168 0 2.0083E8 19940118 10101
3710100000000 22608716 1 2.0083E8 20010601 19940117
;
run;
data tty1;
set qc2;
enddt_new=last_use;
if enddt_new=10101 then enddt_new=99991231;
run;
proc sql;
proc sort data=tty1;
by cm13 descending first_use descending enddt_new ;
run;
I'm expecting to see first record with max first_use and max last_use.but it isnt the case
What is the proc sql; statement doing there?
Your sort will put the 2nd record first. The third part of the by statement will have no effect since it is sorting by enddt_new WITHIN descending first use
Hi,
I do not understand why you have a "proc sql" in your code, it is useless.
What does the following code gives ?
data qc2;
input cm13 key_str key_expire feed_key first_use last_use;
cards;
3710100000000 102158168 0 2.0083E8 19940118 10101
3710100000000 22608716 1 2.0083E8 20010601 19940117
;
run;
data tty1;
set qc2;
if last_use=10101 then enddt_new=99991231;
else enddt_new=last_use;
run;
proc sort data=tty1;
by cm13 descending enddt_new descending first_use ;
run;
Proc sql is a typo.
I want the dataset that is sorted on enddt_new and first_use both in descending order.
Show the resulting file you want to achieve from your example.
If you want to see maximum values, sort is the wrong tool for you.
proc sql;
create table tty2 as
select cm3,
max(enddt_new) as enddt_new,
max(first_use) as first_use,
from tty1
group by cm3
;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.