Macro - Get Data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro - Get Data

Adam Martin-7
Hi all

This is my first step into the realm of marcos.

My objective is to pull a SAS file in, run frequencies, and then save it as a SPSS file. I need to do this over many files.

This is the furthest I have made it, but it's not running.
>>>
DEFINE !convert (mydate=!CMDEND)

!ENDDEFINE.

GET
SAS DATA='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sas7bdat'.
DATASET NAME DataSet1 WINDOW=FRONT.
FREQUENCIES
  VARIABLES=RECH_REVENUE  /FORMAT=NOTABLE
  /STATISTICS=SUM
  /ORDER=  ANALYSIS .
SAVE OUTFILE='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sav'
 /COMPRESSED.

!convert mydate = week200752.
>>>

The above is only specifying one date. The full file path is:

C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\week200752.sas7bdat.

Thanks!

Regards
Adam

--
Cell: +27 84 777 1801
Website: http://www.sigmasurveys.co.za
Blog: http://www.sigmasurveys.co.za/resources
Reply | Threaded
Open this post in threaded view
|

Re: Macro - Get Data

Marks, Jim

Adam:

There are two quick fixes I can see:

 

1) You need to put your GET DATA, FREQUENCIES and SAVE commands within the macro.

2) You need to handle the strings for the files within the macro (they need to be concatentated and placed within ‘ marks).

 

Not tested:

 

DEFINE !convert (mydate = !CMDEND).

 

GET SAS DATA =

  !QUOTE(!CONCAT(‘C:\documents and settings\adam.martin\desktop\weekly recharges\’,!mydate,’.sas7bdat’))

.

DATASET NAME = !mydate WINDOW = FRONT.

 

FREQUENCIES VARIABLES = rech_revenue /FORMAT = NOTABLE

   /STATISTICS = SUM  /ORDER = ANALYSIS.

 

SAVE OUTFILE =

  !QUOTE(!CONCAT(‘C:\documents and settings\adam.martin\desktop\weekly recharges\’,!mydate,’.saV’)) /

  COMPRESSED

.

 

!ENDDEFINE.

 

!convert mydate = week200752 .

 

Hope this helps.

 

--jim

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Adam Martin
Sent: Friday, January 30, 2009 10:32 AM
To: [hidden email]
Subject: Macro - Get Data

 

Hi all

This is my first step into the realm of marcos.

My objective is to pull a SAS file in, run frequencies, and then save it as a SPSS file. I need to do this over many files.

This is the furthest I have made it, but it's not running.
>>>
DEFINE !convert (mydate=!CMDEND)

!ENDDEFINE.

GET
SAS DATA='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sas7bdat'.
DATASET NAME DataSet1 WINDOW=FRONT.
FREQUENCIES
  VARIABLES=RECH_REVENUE  /FORMAT=NOTABLE
  /STATISTICS=SUM
  /ORDER=  ANALYSIS .
SAVE OUTFILE='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sav'
 /COMPRESSED.

!convert mydate = week200752.
>>>

The above is only specifying one date. The full file path is:

C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\week200752.sas7bdat.

Thanks!

Regards
Adam

--
Cell: +27 84 777 1801
Website: http://www.sigmasurveys.co.za
Blog: http://www.sigmasurveys.co.za/resources

Reply | Threaded
Open this post in threaded view
|

Re: Macro - Get Data

Adam Martin-7
Thanks Jim.

Progress!

The only thing I had to change was DATASET NAME as it does not require the " = ".

Appreciate the quick response.

Regards
Adam

2009/1/30 Marks, Jim <[hidden email]>

Adam:

There are two quick fixes I can see:

 

1) You need to put your GET DATA, FREQUENCIES and SAVE commands within the macro.

2) You need to handle the strings for the files within the macro (they need to be concatentated and placed within ' marks).

 

Not tested:

 

DEFINE !convert (mydate = !CMDEND).

 

GET SAS DATA =

  !QUOTE(!CONCAT('C:\documents and settings\adam.martin\desktop\weekly recharges\',!mydate,'.sas7bdat'))

.

DATASET NAME = !mydate WINDOW = FRONT.

 

FREQUENCIES VARIABLES = rech_revenue /FORMAT = NOTABLE

   /STATISTICS = SUM  /ORDER = ANALYSIS.

 

SAVE OUTFILE =

  !QUOTE(!CONCAT('C:\documents and settings\adam.martin\desktop\weekly recharges\',!mydate,'.saV')) /

  COMPRESSED

.

 

!ENDDEFINE.

 

!convert mydate = week200752 .

 

Hope this helps.

 

--jim

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Adam Martin
Sent: Friday, January 30, 2009 10:32 AM
To: [hidden email]
Subject: Macro - Get Data

 

Hi all

This is my first step into the realm of marcos.

My objective is to pull a SAS file in, run frequencies, and then save it as a SPSS file. I need to do this over many files.

This is the furthest I have made it, but it's not running.
>>>
DEFINE !convert (mydate=!CMDEND)

!ENDDEFINE.

GET
SAS DATA='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sas7bdat'.
DATASET NAME DataSet1 WINDOW=FRONT.
FREQUENCIES
  VARIABLES=RECH_REVENUE  /FORMAT=NOTABLE
  /STATISTICS=SUM
  /ORDER=  ANALYSIS .
SAVE OUTFILE='C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\!mydate.sav'
 /COMPRESSED.

!convert mydate = week200752.
>>>

The above is only specifying one date. The full file path is:

C:\Documents and Settings\adam.martin\Desktop\Weekly Recharges\week200752.sas7bdat.

Thanks!

Regards
Adam

--
Cell: +27 84 777 1801
Website: http://www.sigmasurveys.co.za
Blog: http://www.sigmasurveys.co.za/resources




--
Cell: +27 84 777 1801
Website: http://www.sigmasurveys.co.za
Blog: http://www.sigmasurveys.co.za/resources