Date: Tue, 19 Jan 1999 21:17:22 -0500
Reply-To: Howard Schreier <HSchreier@USA.NET>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Howard Schreier <HSchreier@USA.NET>
Subject: Re: help with parsing (using translate and/or scan function)
Content-Type: text/plain; charset="iso-8859-1"
There are many ways to get this done.
My choice is
date = input(substr(record,index(record,'.')-6,6),yymmdd6.);
which finds the first period then extracts the substring beginning six
characters to the left of it. It should work as long as there is no period
in the prefix.
> Date: Tue, 12 Jan 1999 00:39:38 GMT
> From: Jennifer.Soller@BGLOBAL.COM
> Subject: help with parsing (using translate and/or scan function)
>
> Hello to all. Your help has been very useful in the past. Hopefully,
someone
> can help me with this.....
>
> I have a filename dump from a Unix directory and I want to parse out the
date
> and turn it into a SAS date. For example:
>
> RECORD DATE
> jennifer981101.plainfile -> 14184
> jennifer981102.plainfile -> 14185
> jennifer981103.plainfile -> 14186
>
> I figured out how to do this:
> DATE = INPUT(PUT(SCAN(SCAN(RECORD,1,"."),1,"jennifer"),$6.),YYMMDD6.);
>
> In actuality, the prefix to the filename changes for different runs of
this
> program, so it becomes a macro variable:
>
> %LET PREFIX = jennifer;
> DATE = INPUT(PUT(SCAN(SCAN(RECORD,1,"."),1,"&PREFIX"),$6.),YYMMDD6.);
>
> This worked fine for months -- until somebody started using a prefix that
had
> a number in it. For example:
>
> PREFIX = jenn3file
>
> RECORD DATE SCAN RETURN
> jenn3file981101.plainfile -> 14184 -> 981101
> jenn3file981102.plainfile -> 14185 -> 981102
> jenn3file981103.plainfile -> . -> 98110
>
> I know *why* this doesn't work: the scan function looks for any occurance
of
> any of the values in the delimiter argument -- since 3 is in the prefix
and
> the date the scan function just returns the portion that does not contain
any
> 3. The translate function works the same way.
>
> Any ideas as to how to get around this?
>
> Thanks in advance.
>
> -jennifer.
>
> Jennifer Soller
> Advanced Strategies and Research
> Barclays Global Investors
> jennifer.soller@barclaysglobal.com
|