1. %let a=10;
data new;
set old;
where b=%eval(&a-1);
run;
2.
%macro byweek(a, b);
proc summary data=&a.week;
by system cat name;
var absent enrolled;
output out=&b._out sum=&b._absent &b._enrolled;
run;
data &b._out2;
set &b._outs;
&b._rate=(&b._absent*100)/&b._enrolled;
keep system cat name
&b._absent &b._enrolled &b._rate;
run;
data &b._out3;
merge &b._out2 list;
by system cat name;
run;
%mend;
Thank you so much .
The folks most likely to help probably don't know SAS very well, if at
all. So it would help if you added comments explaining what the SAS
code is doing.
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."
1. %let a=10: creates a macro variable "a" and assign value 10 to
this marco variable.
b=%eval(&a-1): %eval makes the arithmetic possible. it equals b=
(10-1)=9
2. Create a new data set new based on the old data set.
&b: refers to macro variable b.
Proc summary: we can generate the summary statistics using it
I tried to convert this SAS code to the SPSS syntax and got the
following SPSS syntax. But I don't know how to refer the macro
varibale in SPSS, so I am wondering if you can replace the &b with
appropriate spss syntax. Please correct me if I made some mistakes.
DEFINE !byweek(a, b)
GET FILE=”F:\ &a.week”.
SORT CASES BY system cat name.
AGGREGATE
/OUTFILE= * MODE=ADDVARIABLES
/BREAK=system cat name
/&b._labsent &b._enrolled =SUM(absent enrolled)
COMPUTE &b._rate=(&b._absent*100)/&b._enrolled.
SAVE OUTFILE='C: &b._out2school.sav'
/KEEP= system cat name &b._absent &b._enrolled &b._rate.
GET FILE='F:\listschool.sav'.
SORT CASE BY system cat name.
GET FILE='F:\&b._out2school.sav'.
SORT CASE BY system cat name.
MATCH FILES/FILE=*
/FILE='name'
/BY system cat name.
EXECUTE.
!ENDDEFINE.
!byweek a=current b=curr.
!byweek a=previous b=prev.
3.How can we connect SPSS results with MS-Excel using DDE (Dynamic
data exchange).
Thanks again
There is no SPSS equivalent of %eval AFAIK. One has to resort to
tricks to do arithmetic in the macro language. I believe there are
some examples on Raynald's website (spsstools.net), and probably in
the archives of this group.
>
> 2. Create a new data set new based on the old data set.
> &b: refers to macro variable b.
> Proc summary: we can generate the summary statistics using it
>
> I tried to convert this SAS code to the SPSS syntax and got the
> following SPSS syntax. But I don't know how to refer the macro
> varibale in SPSS, so I am wondering if you can replace the &b with
> appropriate spss syntax. Please correct me if I made some mistakes.
I don't have a lot of time, but here are a couple observations (see
below).
>
> DEFINE !byweek(a, b)
DEFINE !byweek (a=!TOKENS(1) /
b=!TOKENS(1))
>
> GET FILE=”F:\ &a.week”.
> SORT CASES BY system cat name.
>
> AGGREGATE
> /OUTFILE= * MODE=ADDVARIABLES
> /BREAK=system cat name
> /&b._labsent &b._enrolled =SUM(absent enrolled) .
COMPUTE is a separate command. You need the command terminator I added
to the previous line.
> COMPUTE &b._rate=(&b._absent*100)/&b._enrolled.
>
> SAVE OUTFILE='C: &b._out2school.sav'
> /KEEP= system cat name &b._absent &b._enrolled &b._rate.
>
> GET FILE='F:\listschool.sav'.
DATASET NAME name.
* I assmume listschool.sav is the file you are trying merge below.
> SORT CASE BY system cat name.
> GET FILE='F:\&b._out2school.sav'.
> SORT CASE BY system cat name.
> MATCH FILES/FILE=*
> /FILE='name'
> /BY system cat name.
> EXECUTE.
>
> !ENDDEFINE.
> !byweek a=current b=curr.
> !byweek a=previous b=prev.
>
> 3.How can we connect SPSS results with MS-Excel using DDE (Dynamic
> data exchange).
I don't know.
>
> Thanks again
HTH.
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/