DATA Step, Macro, Functions and more

Proc sort

Reply
Super Contributor
Posts: 647

Proc sort

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

PROC Star
Posts: 7,363

Re: Proc sort

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

Frequent Contributor
Posts: 127

Re: Proc sort

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;

Super Contributor
Posts: 647

Re: Proc sort

Proc sql is a typo.

I want the dataset that is sorted on enddt_new and first_use both in descending order.

PROC Star
Posts: 7,363

Re: Proc sort

Show the resulting file you want to achieve from your example.

Super User
Posts: 5,256

Re: Proc sort

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;

Data never sleeps
Ask a Question
Discussion stats
  • 5 replies
  • 208 views
  • 1 like
  • 4 in conversation