BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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

5 REPLIES 5
art297
Opal | Level 21

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

Florent
Quartz | Level 8

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;

SASPhile
Quartz | Level 8

Proc sql is a typo.

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

art297
Opal | Level 21

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

LinusH
Tourmaline | Level 20

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 820 views
  • 1 like
  • 4 in conversation