BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Dear all,

assuming I have this  dataset and I want to find the range of the ages.

If I want the range to be displayed like (23-94). How do I do that?

data have;
    infile datalines truncover ;
  input age;
datalines;
23
43

55
60
94
55
60
; run

 

4 REPLIES 4
andreas_lds
Jade | Level 19

What do expect as result exactly?

 

Untested:

data want;
  set have end=jobDone;
  retain min max;
  if _n_ = 1 then do;
    min = 99999;
    max = 0;
  end;

  min = min(min, age);
  max = max(max, age);

  if jobDone then do;
    put min " - " max;
  end;
run;
Ksharp
Super User
data have;
    infile datalines truncover ;
  input age;
datalines;
23
43
.
55
60
94
55
60
;


proc sql;
select cats('(',min(age),'-',max(age),')') as range label='#'
 from have;
quit;
Anita_n
Pyrite | Level 9

@andreas_lds @Ksharp @Kurt_Bremser : Thankyou all for the reply, I will try that

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
  • 4 replies
  • 1044 views
  • 3 likes
  • 4 in conversation