DATA Step, Macro, Functions and more

Do loop to extract info from multiple consecutive rows.

Reply
Occasional Contributor
Posts: 9

Do loop to extract info from multiple consecutive rows.

Hi,
I need to build a report about several cognos' cubes (dimensions,
levels measures etc..) from *.mdl files (ascii type) then contain the
structure.
First I import xxxx.mdl file and create variable x, than I exstract
cube infos by scan(x, ....), because all infos are key-substring from
first collumn. when I meet one key value I know the info is on the
next double quoted substring.
For example:

data stat_cube;
infile &infile truncover;
input x $5000.;
retain name datasource;
length datasource $30.;
if x NE '';
test=scan(x,1);
select (test);
when('Name') do;
name=scan(x,2,'"');
valore=name;
datasource='';
end;
when('DataSource') do;
datasource=scan(x,2,'"');
valore=datasource;
end;
when('OrgName') do;
orgname=scan(x,2,'"');
valore=orgname;
end;
when('Dimension') do;
dimension=scan(x,2,'"');
valore=dimension;
end;
when('Root') do;
root=scan(x,2,'"');
valore=root;
end;
when('Levels') do;
levels=scan(x,2,'"');
valore=levels;
end;
when('Measure') do; /*** partial code ***/
measure=scan(x,2,'"');
valore=measure;
end;
otherwise delete;
end;
if test='Name' then DataSource='';
run;

Except for 'Measure', every info is on the row where is the key
value and the uppuer program retrieve all I need.
Sometime for 'Measure' infos are distribuited also on the next rows
and, for some strange reason, cognos could brack it on the successive
row.
The sample below is from an mdl input file:

******* original row data *******
.
.


Measure 2687 "Margini" Storage Default OutPutScale 0 Decimals 0
ReverseSign False
IsCurrency False IsFolder True DrillThrough False EndList

Measure 3041 "Var.% Mrg RC vs RP" Label "Var.% Mrg RC vs RP" ShortName
"Var.% Mrg RC vs RP"
Calc ( "MRG_RAC_RC@2143" - "MRG_RAC_RP@2973" ) / "MRG_RAC_RP@2973"
Timing After_Rollup
"ShortName"='Var.% Mrg RC vs RP' , "Calc"=( "MRG_RAC_RC@2143" -
"MRG_RAC_RP@2973" ) / "MRG_RAC_RP@2973" and "MeasureInfo"="Margine
costi / ricavi finanziari progressivo al mese corrente dell'ann"
"o precedente." DrillThrough False

.
.
*******************************

For first bloc lines the program meet "Measure" and assign his value
at valore=Margini.
For the second I nedd estract also "ShortName" => valore2='Var.% Mrg
RC vs RP' , "Calc" => valore3=( "MRG_RAC_RC@2143" -
"MRG_RAC_RP@2973" ) / "MRG_RAC_RP@2973" and "MeasureInfo"="Margine
costi / ricavi finanziari progressivo al mese corrente dell'anno
precedente."
As you can see on the second bloc info for "MeasureInfo" is splitted
on 2 consecutive lines.
I suppose for read the varius values for "Measure" I must use some do
loop (do while(...)) that scan for all lines relative to the "Measure"
bloc.
Have you any tips about?
Thank you in advance.

Costas
Occasional Contributor
Posts: 9

Re: Do loop to extract info from multiple consecutive rows.

Hi, no tips about?

Costas
Super Contributor
Super Contributor
Posts: 3,174

Re: Do loop to extract info from multiple consecutive rows.

Yes - a looping DO WHILE (); END; code paragraph will do the job quite nicely.

Suggested Google advanced search argument for the SAS.COM support site which has many code samples as well as SAS-hosted DOC:

parse multiple data lines input site:sas.com


Scott Barry
SBBWorks, Inc.

Example reference from search results:
Using SAS® to Parse External Data
Andrew T. Kuligowski, The Nielsen Company
http://www2.sas.com/proceedings/forum2008/190-2008.pdf
Ask a Question
Discussion stats
  • 2 replies
  • 142 views
  • 0 likes
  • 2 in conversation