|
Dear all,
I'm trying to write a macro and it's almost working. Only, the !varlist is not built up the way I'd like it. Could anybody please have a look? TIA! Ruben set mpr off. def !readxls9() !do !lv1 =3 !to 9 get data /type=xls /file='Respons 2009.xls' /sheet=index !lv1. datas nam !con('data',!lv1). comp month=!lv1. !let !varlist=!concat('fil data',!lv1,'/',!varlist) !doend add fil !varlist. datas clo all. datas nam totaal. !end. set mpr on. !readxls9. New Windows 7: Simplify what you do everyday. Find the right PC for you. |
|
Hi Ruben, A little hard to tell, but doesn’t your assignment… !let !varlist=!concat('fil data',!lv1,'/',!varlist) … redefine !varlist before !varlist is defined in the first loop?
What do your error messages say (when expand is on)? From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Ruben van den Berg Dear all, New
Windows 7: Simplify what you do everyday. Find the right PC for
you. |
|
Dear Bob,
Thanks for your reply. The macro runs smoothly until the add files command. This doesn't work because the varlist is not what I'd like it to be. More precisely, when add files is encountered, it is written out as: add fil fil data9/!varlist. which obviously renders an error. I thought the '!varlist trick' would work because it did work in a rather similar way in the syntax below. Perhaps I should try to put the add files command within the loop so I don't have to accumulate dataset names but a single dataset to which the new datasets are added and then closed. TIA once again! Ruben (Syntax where !varlist trick works) new fil. inp pro. loop id=1 to 100. end cas. end loop. end fil. end inp pro. exe. do rep bla=bla.1 to bla.25/bli=bli.1 to bli.25. comp bla=0. comp bli=0. end rep. exe. define !reorder () !let !varlist='' !do !t2=1 !to 25 !let !varlist=!concat(!varlist,' bla.',!t2,' bli.',!t2) !doend match files file = * /keep id !varlist. exe. !end. set mpr on. !reorder. Date: Fri, 27 Nov 2009 09:30:42 -0500 From: [hidden email] Subject: RE: Macro trouble To: [hidden email]; [hidden email] Hi Ruben,
A little hard to tell, but doesn’t your assignment…
!let !varlist=!concat('fil data',!lv1,'/',!varlist) … redefine !varlist before !varlist is defined in the first loop? What do your error messages say (when expand is on)?
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Dear all, New Windows 7: Simplify what you do everyday. Find the right PC for you. Express yourself instantly with MSN Messenger! MSN Messenger |
|
Administrator
|
But notice that in that syntax, !varlist is set to '' (the line in boldface above) before you get to the line where it has new stuff concatenated with it. I don't think you ever defined !varlist that way in the new syntax that is causing problems.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
|
In reply to this post by Ruben Geert van den Berg
Hi Ruben, Based on an example with sheets 1-3, this worked at my end… PRESERVE. SET MEXPAND ON /MPRINT ON. DATASET CLOSE ALL. DEFINE !readxls9() !let !varlist = !blanks(1) /* initializes !varlist so it can be
concatenated later !do !lv1 = 1 !to 3 get data /type=xls /file='Respons 2009.xls' /sheet=index !lv1. comp month =!lv1. execute. /* need execute, as dataset doesn't force data to be
read dataset name !concat('data',!lv1). !let !varlist=!concat(!varlist,"/",'file data',!lv1) !doend add files !varlist. execute. /* needed for add files !ENDDEFINE. !readxls9. dataset close all. dataset name totaal. RESTORE. From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Ruben van den Berg Dear all, New
Windows 7: Simplify what you do everyday. Find the right PC for
you. |
|
Dear Bob,
Thank you, it works fine indeed! Honestly, I managed to fix it last Friday. It comes in handy since my colleague has to read in this workbook monthly - we'll just expand the loop next month :-D Kind regards, Ruben Date: Mon, 30 Nov 2009 13:23:50 -0500 From: [hidden email] Subject: Re: Macro trouble To: [hidden email] Hi Ruben,
Based on an example with sheets 1-3, this worked at my end…
PRESERVE. SET MEXPAND ON /MPRINT ON. DATASET CLOSE ALL. DEFINE !readxls9() !let !varlist = !blanks(1) /* initializes !varlist so it can be concatenated later !do !lv1 = 1 !to 3 get data /type=xls /file='Respons 2009.xls' /sheet=index !lv1. comp month =!lv1. execute. /* need execute, as dataset doesn't force data to be read dataset name !concat('data',!lv1). !let !varlist=!concat(!varlist,"/",'file data',!lv1) !doend add files !varlist. execute. /* needed for add files
!ENDDEFINE. !readxls9.
dataset close all. dataset name totaal. RESTORE.
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ruben van den Berg
Dear all, New Windows 7: Simplify what you do everyday. Find the right PC for you. New Windows 7: Find the right PC for you. Learn more. |
| Free forum by Nabble | Edit this page |
