BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
I have a variables id and address

id address
1 main road
2 stret
3 bazar

now i want the min and max length of the observations in the variable address.
so finally the out should be like this min length(5) and max length(9)
2 REPLIES 2
Flip
Fluorite | Level 6
A simple SQL query can get you that:

proc sql;
select cats( 'min length(' , put(min(length(address)), best. -l), ')') ,
cats( 'max length(' , put(max(length(address)), best.-l), ')') from xxx;
quit;

One could also do it in a datastep :

data two;
set one end = eof;
retain big 0;
retain small 10000;
size = length(address);
big = max(big, size);
small = min(small, size);
if eof then output;
run;

Take your pick.
R_Win
Calcite | Level 5
Thanks for your Reply

Message was edited by: sas_user



data x;
input a$30.;
cards;
satish hjgjhgjhg
sam jhbhkjjjjkl lknjkl
ganesh
avb
;
run;


data y(drop=a);
retain min 100;
retain max 0;
set x end=s;
min=min(min,length(a));
max=max(max,length(a));
if s then output;
run;
proc print;
run; Message was edited by: sas_user

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1604 views
  • 0 likes
  • 2 in conversation