Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert SAS code into SPSS syntax

1,909 views
Skip to first unread message

Lily

unread,
May 10, 2009, 1:40:45 AM5/10/09
to
Hey guys, I am new to SPSS macro. Now I have some SAS code and try to
convert them to SPSS syntax.It is really an emergency. Could anybody
help me out? The SAS code are as follows:

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 .

Bruce Weaver

unread,
May 11, 2009, 11:35:08 AM5/11/09
to


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."

Lily

unread,
May 11, 2009, 11:35:29 PM5/11/09
to
Thanks for your reply Bruce. Well, the description for the SAS code is
as follos:

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

Bruce Weaver

unread,
May 12, 2009, 9:24:35 AM5/12/09
to
On May 11, 11:35 pm, Lily <pointbreak3...@gmail.com> wrote:
> Thanks for your reply Bruce. Well, the description for the SAS code is
> as follos:
>
> 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

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.

Lily

unread,
May 13, 2009, 9:44:11 PM5/13/09
to
Thanks Bruce, it does help a lot. Have a nice evening.

> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/

bbogda...@gmail.com

unread,
Apr 22, 2016, 12:21:21 AM4/22/16
to
what would be the spss equivalent of SAS retain statement ?

Bruce Weaver

unread,
Apr 27, 2016, 8:40:21 AM4/27/16
to
On Friday, April 22, 2016 at 12:21:21 AM UTC-4, BOGDAN BOGDANOVIC wrote:
> what would be the spss equivalent of SAS retain statement ?

It is said that God and helps those who help themselves. The same might be said of members of this forum.

TRANSLATION: You will be far more likely to get help if you explain what "retain" does in SAS. Provide a small small example showing the current state of your data, and the desired state after "retain", for example. Or provide a link to a page that explains it. Don't make us do the work for you.

HTH.

David Marso

unread,
Apr 27, 2016, 5:14:07 PM4/27/16
to
Bruce,
I answered this question 2 threads below (Either LEAVE or LAG depending upon context -which is not provided-.
BOGDAN ! please don't double post and follow up on your queries when asked for clarification.
0 new messages