Help using Base SAS procedures

Min and Max length of the observations in a varible

Reply
Regular Contributor
Posts: 229

Min and Max length of the observations in a varible

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)
Super Contributor
Posts: 359

Re: Min and Max length of the observations in a varible

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.
Regular Contributor
Posts: 229

Re: Min and Max length of the observations in a varible

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
Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 0 likes
  • 2 in conversation