Date: Wed, 20 Dec 2000 09:49:19 -0800
Reply-To: "Terjeson, Mark" <TerjeMW@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TerjeMW@DSHS.WA.GOV>
Subject: Re: Output II
Content-Type: text/plain; charset=iso-8859-1
Hi again,
A couple more late thoughts. If NUM is just
for computing the 2char chunks, then it is not
needed. If NUM was going to be used for other
purposes, then you'll have to add it back in.
*Assuming* that your claim strings are always
in groups of two, you can just use the length()/2.
If so, you can always key of off the looping index
(in your case variable-i) and compute the size
of the subsgroup of desired characters (in your
case below, 2 letter groups). This makes all of
the IF statements unnecessary.
You could use a BY statement on the DO loop
to increment by two, but this method (of computing
the increments) allows you to have the increments
of variable-i to use for other purposes simultaneously,
such as sequential numbering like the new variable
GROUP below.
So streamlining could be something like this:
data test(drop=i);
input @1 code $2.
@3 desc $15.
@18 claim $8.
;
do i = 1 to length(claim)/2 ;
* substring for each set ;
press=substr(claim,(i*2)-1,2) ;
group = i;
output ; * output the record ;
end ;
cards ;
75cows and horsesmm
76dogs and cats mtxl
77mice and men mzroxl
;
run ;
Mark
-----Original Message-----
From: Terjeson, Mark [mailto:TerjeMW@DSHS.WA.GOV]
Sent: Wednesday, December 20, 2000 9:20 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Output
Hi Foster,
I'm not sure what your NUM variable is or is to be,
but to get all the 2char letters in PRESS you need
to change this line:
press=substr(claim,num,2) ;
to:
press=substr(claim,(i*2)-1,2) ;
Let us know if there is another variable we need to fix.
data test;
retain num 1;
input @1 code $2.
@3 desc $15.
@18 claim $8.
;
chars = length(claim) ; * find the length of the var ;
** divide by 2 to find the number of sets ;
if chars > 1 then chary = chars/2 ;
do i = 1 to chary ;
if i = 1 then press = substr(claim,1,2) ;
else if i > 1 then
do;
* the first pass should equal 3 (1+2), ;
* and increment by 2 ;
num = num + 2 ;
* substring for each set ;
press=substr(claim,(i*2)-1,2) ;
end ;
output ; ** output the record ?????? ;
end ;
put _all_ ;
cards ;
75cows and horsesmm
76dogs and cats mtxl
77mice and men mzroxl
;
run ;
Hope this is helpful,
Mark Terjeson
Washington State Department of Social and Health Services
Division of Research and Data Analysis (RDA)
mailto:terjemw@dshs.wa.gov
-----Original Message-----
From: Kerrison, Foster [mailto:FKerrison@NT.DMA.STATE.MA.US]
Sent: Wednesday, December 20, 2000 8:49 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Output
Seasons greeting to all SASslers,
I have a problem with some output - see code below - that I would appreciate
some help on.
What I am trying to do is to produce records for each set in claim. A set is
equal to two letters. So MM would be 1, MMMT would be 2 and so on. What I
want to do is to output 1 record if there is one pair, 2 records if there
are two pairs, and so on. The values in the other vars should not change,
but should appear in each record.
TIA,
Foster Kerrison
data tesst ;
retain num 1;
input code $2. @ 3 desc $15. @ 18 claim $8. ;
chars = length(claim) ; * find the length of the var ;
if chars > 1 then chary = chars/2 ; ** divide by 2 to find the number of
sets ;
do i = 1 to chary ;
if i = 1 then press = substr(claim,1,2) ;
else if i > 1 then do;
num = num + 2 ; * the first pass should equal 3 (1+2), and increment
by 2 ;
press=substr(claim,num,2) ; ** substring for each set ;
end ;
output ; ** output the record ?????? ;
end ;
put _all_ ;
cards ;
75cows and horsesmm
76dogs and cats mtxl
77mice and men mzroxl
;
run ;