Date: Sat, 8 Nov 2008 18:37:14 -0500
Reply-To: Joe Whitehurst <joewhitehurst@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Whitehurst <joewhitehurst@GMAIL.COM>
Subject: Re: read in observations one by one
In-Reply-To: <6795419c-672e-4725-b521-c4c5462f1b8c@b2g2000prf.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
fuqiang,
The following snippet from a Macro shows one way to do what you want except
in this case each observation in the parameters02 has all the parameters to
completely customize several PROC REPORTS.
%macro Generate_Profit_Reports; *Macro begins;
%let title_font_size=1;
%let font_size=1;
%let cellwidth=50pt;
%let s1_2_number_of_variables = 16; *number of variables in strips 1 and
2;
%let s3_4_number_of_variables = 9; *number of variables in strips 3 and
4;
%let
profit_report_parameters_dsid=%sysfunc(open(profdata.parameters02,v));
%let
number_of_profit_reports=%sysfunc(attrn(&profit_report_parameters_dsid,nobs));
%let closerc=%sysfunc(close(&profit_report_parameters_dsid));
*let number_of_profit_reports=10;
%do i=1 %to &number_of_profit_reports; *Beginning of Outer Loop;
data _null_;
report_number=&i;
set profdata.parameters02 point=report_number;
s1_libname='profdata';
s2_libname='profdata';
s3_libname='profdata';
s4_libname='profdata';
call symput("s1_libname",trim(s1_libname));
call symput("s2_libname",trim(s2_libname));
call symput("s3_libname",trim(s3_libname));
call symput("s4_libname",trim(s4_libname));
call symput("s1_dataset_name",trim(s1_dataset_name));
call symput("s2_dataset_name",trim(s2_dataset_name));
call symput("s3_dataset_name",trim(s3_dataset_name));
call symput("s4_dataset_name",trim(s4_dataset_name));
call symput("s1_where",compbl(s1_where));
call symput("s2_where",compbl(s2_where));
call symput("s3_where",compbl(s3_where));
call symput("s4_where",compbl(s4_where));
call symput("s1_lefttitle1",trim(s1_lefttitle1));
call symput("s1_midtitle1", trim(s1_midtitle1));
call symput("s1_righttitle1",trim(s1_righttitle1));
call symput("s1_lefttitle2",trim(s1_lefttitle2));
call symput("s1_midtitle2",trim(s1_midtitle2));
call symput("s1_righttitle2",trim(s1_righttitle2));
call symput("s1_lefttitle3",trim(s1_lefttitle3));
call symput("s1_midtitle3",trim(s1_midtitle3));
call symput("s1_righttitle3",trim(s1_righttitle3));
call symput("s1_rowlabel",trim(s1_rowlabel));
call symput("s2_rowlabel",trim(s2_rowlabel));
call symput("s3_rowlabel",trim(s3_rowlabel));
call symput("s4_rowlabel",trim(s4_rowlabel));
call
symput("s1_rowlabel_header_text",trim(s1_rowlabel_header_text));
call
symput("s2_rowlabel_header_text",trim(s2_rowlabel_header_text));
call
symput("s3_rowlabel_header_text",trim(s3_rowlabel_header_text));
call
symput("s4_rowlabel_header_text",trim(s4_rowlabel_header_text));
array s1_numeric_variables{*}
s1_numeric_variable1-s1_numeric_variable17;
array s2_numeric_variables{*}
s2_numeric_variable1-s2_numeric_variable17;
array s3_numeric_variables{*}
s3_numeric_variable1-s3_numeric_variable17;
array s4_numeric_variables{*}
s4_numeric_variable1-s4_numeric_variable17;
array s1_column_headers{*}
s1_column_header1-s1_column_header17;
array s2_column_headers{*}
s2_column_header1-s2_column_header17;
array s3_column_headers{*}
s3_column_header1-s3_column_header17;
array s4_column_headers{*}
s4_column_header1-s4_column_header17;
do i=1 to dim(s1_numeric_variables);
call
symput("s1_numeric_variable"||left(i),left(s1_numeric_variables(i)));
end;
do i=1 to dim(s2_numeric_variables);
call
symput("s2_numeric_variable"||left(i),left(s2_numeric_variables(i)));
end;
do i=1 to dim(s3_numeric_variables);
call
symput("s3_numeric_variable"||left(i),left(s3_numeric_variables(i)));
end;
do i=1 to dim(s4_numeric_variables);
call
symput("s4_numeric_variable"||left(i),left(s4_numeric_variables(i)));
end;
do i=1 to dim(s1_column_headers);
* s1_column_headers(i)=translate(s1_column_headers(i),'
','@');
call
symput("s1_column_header"||left(i),left(s1_column_headers(i)));
end;
do i=1 to dim(s2_column_headers);
* s2_column_headers(i)=translate(s2_column_headers(i),'
','@');
call
symput("s2_column_header"||left(i),left(s2_column_headers(i)));
end;
do i=1 to dim(s3_column_headers);
* s3_column_headers(i)=translate(s3_column_headers(i),'
','@');
call
symput("s3_column_header"||left(i),left(s3_column_headers(i)));
end;
do i=1 to dim(s4_column_headers);
* s4_column_headers(i)=translate(s4_column_headers(i),'
','@');
call
symput("s4_column_header"||left(i),left(s4_column_headers(i)));
end;
stop; *end of point= statement ;
run; *end of data _null_ step;
%let proclabel1=%str(Produto: &s1_midtitle1 Canal: &s1_righttitle1 Report
Date: &s1_lefttitle2 Policy: &s1_midtitle2 Subcanal: );
%let proclabel2=%str(&s1_righttitle2 Plan: &s1_lefttitle3 Status:
&s1_midtitle3 Cobert: &s1_righttitle3);
ods noproctitle;
ods proclabel "&proclabel1 &proclabel2";
ODS PDF(ID=MKTBPDF) startpage=now;
title1 j=left font='Times New Roman' bold color=black h=&title_font_size
"&s1_lefttitle1 "
font='Times New Roman' bold color=black
h=&title_font_size "Produto: &s1_midtitle1 "
font='Times New Roman' bold color=black
h=&title_font_size "Canal: &s1_righttitle1 "
"
***** CONFIDENTIAL - FOR INTERNAL USE ONLY *****";
title2 j=left font='Times New Roman' bold color=black h=&title_font_size
"Report Date: &s1_lefttitle2 "
font='Times New Roman' bold color=black
h=&title_font_size "Policy: &s1_midtitle2 "
font='Times New Roman' bold color=black
h=&title_font_size " Subcanal: &s1_righttitle2 " ;
title3 j=left font='Times New Roman' bold color=black h=&title_font_size
"Plan: &s1_lefttitle3 "
font='Times New Roman' bold color=black
h=&title_font_size " Status: &s1_midtitle3 "
font='Times New Roman' bold color=black
h=&title_font_size " Cobert: &s1_righttitle3 " ;
/* First PROC REPORT prints out strip #1 in a page */
data s1_data%cmpres(&i)(keep=&s1_rowlabel
&s1_numeric_variable1
&s1_numeric_variable2
&s1_numeric_variable3
&s1_numeric_variable4
&s1_numeric_variable5
&s1_numeric_variable6
&s1_numeric_variable7
&s1_numeric_variable8
&s1_numeric_variable9
&s1_numeric_variable10
&s1_numeric_variable11
&s1_numeric_variable12
&s1_numeric_variable13
&s1_numeric_variable14
&s1_numeric_variable15
&s1_numeric_variable16);
set &s1_libname..&s1_dataset_name(&s1_where);
run;
data s1_data%cmpres(&i);
merge profdata.s1_model(in=inmodel)
s1_data%cmpres(&i);
if inmodel;
run;
PROC REPORT data=s1_data%cmpres(&i)
nowd
ls=256
split='@'
SPACING=0
style(HEADER)={foreground=black
just=left
background=white
font_weight=bold
font_size=&font_size}
style(report)={borderwidth=0pt
just=left
rules=all} list
;
column &s1_rowlabel
&s1_numeric_variable1
&s1_numeric_variable2
&s1_numeric_variable3
&s1_numeric_variable4
&s1_numeric_variable5
&s1_numeric_variable6
&s1_numeric_variable7
&s1_numeric_variable8
&s1_numeric_variable9
&s1_numeric_variable10
&s1_numeric_variable11
&s1_numeric_variable12
&s1_numeric_variable13
&s1_numeric_variable14
&s1_numeric_variable15
&s1_numeric_variable16;
define &s1_rowlabel / "&s1_rowlabel_header_text" format=MONyy5.
style(header)=[just=center
font_size=&font_size
font_face="Times New Roman"
font_weight=bold
foreground=white
background=teal]
spacing=0
display
style(column)=[just=center
cellwidth=&cellwidth
font_size=&font_size
font_face="Times New Roman"
font_weight=bold
foreground=white
background=teal];
%do j=1 %to &s1_2_number_of_variables;
define &&s1_numeric_variable&j / "&&s1_column_header&j"
style(header)=[just=center
font_size=&font_size
font_face="Times New
Roman"
font_weight=bold
foreground=white
background=teal]
SPAcING=0
display
style(column)=[just=right
cellwidth=&cellwidth
font_size=&font_size
font_face="Times New
Roman"
font_weight=bold
background=white];
%end;
RUN; *end of first proc report;
title1; title2; title3; *clear out all titles;
On Sat, Nov 8, 2008 at 5:58 PM, <fuqiang0316@gmail.com> wrote:
> i have a macro to finish a certain calculation for a bunch of
> observations. also i have another file which contains the list of the
> observations. i know i can copy the observations into the parameters
> of the macro by hard code. is there a auto way to do this.
> for example i have 5 sales rep, i would like to calculate their sales,
> expense, travel time..., and i have the macro the do this. i can use
> hard code to call macro with different rep's name to do the
> calculation and output with different files. i am wondering if it is
> possible to read in the first name from the list file, do the
> calculation and output, then read in the second rep. and so on. seems
> like i need to use some loop code like do while or do until. but i
> really don't know how to do it. anyone has idea? thanks,
>