Date: Mon, 28 Sep 2009 22:35:38 -0700
Reply-To: Amar Mundankar <amarmundankar@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Amar Mundankar <amarmundankar@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: SAS Subset
Content-Type: text/plain; charset=ISO-8859-1
On Sep 29, 8:12 am, daveyboysmith_...@YAHOO.COM (Dave Smith) wrote:
> hi,
>
> I was wondering if someone can help me,
>
> I have a data set from which I want to subset a part of it based on a var
> called part_num,
>
> if the first 3 characters of part_num are alphabets and the last 4 are
> numeric then I want to output. for example,
>
> part_num
> ABC1234
> ABCD123
> 1551619
> etc etc
>
> the output would only have ABC1234, is there a way to do it?
>
> Thanks
>
> Dave
Hi Dave,
You can try the following.
data one;
input part_num $;
cards;
ABC1234
ABCD123
1551619
242646346
SAAFAFS5353
SSSS3444
4242@#$%^@
sdbf4334
;
data two (keep = part_num);
set one;
first3 = substr(part_num,1,3);
len = length(trim(left(part_num)));
last4 = substr(part_num,len-3);
alpha = notalpha(trim(left(first3)));
digit = notdigit(trim(left(last4)));
*put first3= len= last4= alpha= digit= ;
*put "====================";
if alpha = 0 and digit = 0;
run;
proc print data = two;
run;
Regards,
Amar Mundankar.
|