Date: Tue, 10 Jun 2008 11:40:53 -0500
Reply-To: "data _null_," <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_," <datanull@GMAIL.COM>
Subject: Re: How to change the format of a variable
In-Reply-To: <wLadnRuT2cnQMNPV4p2dnAA@telenor.com>
Content-Type: text/plain; charset=ISO-8859-1
Use a FORMAT that preserves LEADING spaces. $CHAR or $VARYING.
On 6/10/08, Rune Runnestø <rune@fastlane.no> wrote:
> /*
> Thanks to Nat for the help. It works nice with the z5. format.
> But now I have encountered another thing which have to be taken
> care of; that is the output file from the dataset TEST02.
> In the dataset, some of the lines have indentations with spaces, and I want
> those to be kept as indentations also on the file. How do I handle that?
> How do I take care of eventually blank spaces in the beginning of each line?
>
> Rune
> */
>
> data test02;
> set test01;
> length
> saksnr $10.
> year $4.
> seqnr $5.
> nytt_saksnr $10.
> ;
> if substr(line, 1, 8) eq 'SAKSNR.:' then do;
> saksnr = scan(line, 2, ' ');
> year = scan(saksnr, 1, '/');
> seqnr = scan(saksnr, 2, '/');
> * the format z5. writes a number with length 5 and leading zeros;
> new_saksnr = trim(year) || '/' || trim(put(input(seqnr,5.),z5.));
> line = compress('SAKSNR.:#####' || new_saksnr);
> line = translate(line, ' ', '#');
> end;
> keep line;
> file sd_ny pad;
> put line;
> run;
>
> /*
> This is the output file. How do I keep the indentation with
> blank spaces which are in the dataset?
>
> ------------------------
> SAKSNR.: 1994/00003
> ARKIV: 046.5
> TITTEL: something
> SAKSDATO: 06.01.1994
> DOKNR: 1
> DOKTYPE: I
> DOK.TITTEL
> AVSKR.DOK 2
> ------------------------
> SAKSNR.: 1994/00002
> ARKIV: 046.5
> TITTEL: something
> SAKSDATO: 06.01.1994
> DOKNR: 1
> DOKTYPE: I
> DOK.TITTEL
> AVSKR.DOK 2
> ------------------------
> */
>
|