0
How to program a macro that:
Only import a few columns (for example:
ano
,mes
,id
,valor
andmotivo
) of sequential . csv files for SPSS. These files would have type names:DADOS_JAN_2010
,DADOS_FEV_2010
, [...], untilDADOS_DEZ_2019
.Change the lengths of string variables
id
for(a11)
,motivo
for(a32)
, where appropriate (necessary to reconcile the archives of the different years).Stack all these data into a new dataset/table with type name:
DADOS_2010_2019
.
If useful, an example of the data:
| ANO | MÊS | ID | VALOR | MOTIVO |
|------|-----|-------------|-------|--------|
| 2010 | 1 | 12345678910 | 1100 | promo |
| 2010 | 1 | 12345678911 | 200 | faltas |
| 2010 | 1 | 12345678912 | 1450 | meta |
| 2010 | 1 | 12345678913 | 400 | faltas |
| 2010 | 1 | 12345678914 | 1800 | meta |
| 2010 | 1 | 12345678915 | 600 | padrao |
| 2010 | 1 | 12345678916 | 700 | padrao |
| 2010 | 1 | 12345678917 | 800 | meta |
| 2010 | 1 | 12345678918 | 900 | meta |
| 2010 | 1 | 12345678919 | 1000 | promo |
| 2010 | 1 | 12345678920 | 800 | padrao |
For now, I’m opening, stacking and saving the files two by two. But this is repetitive and inefficient. In addition, if more variables need to be included in the future, the whole code needs to be redone. Therefore, I believe that a macro would be the smartest way to accomplish this task.
An example of part of my code so far:
GET DATA /TYPE=TXT
/FILE="C:\Users\luizz\DADOS\DADOS_JAN_2010.csv"
/ENCODING='Locale'
/DELCASE=LINE
/DELIMITERS=";"
/ARRANGEMENT=DELIMITED
/FIRSTCASE=2
/IMPORTCASE=ALL
/VARIABLES=
ANO F4.0
MES F1.0
ID A11
VALOR F4.0
MOTIVO A8.
CACHE.
EXECUTE.
DATASET NAME JAN_2010 WINDOW=FRONT.
ALTER TYPE MOTIVO (a32).
GET DATA /TYPE=TXT
/FILE="C:\Users\luizz\DADOS\DADOS_FEV_2010.csv"
/ENCODING='Locale'
/DELCASE=LINE
/DELIMITERS=";"
/ARRANGEMENT=DELIMITED
/FIRSTCASE=2
/IMPORTCASE=ALL
/VARIABLES=
ANO F4.0
MES F1.0
ID A11
VALOR F4.0
MOTIVO A8.
CACHE.
EXECUTE.
DATASET NAME FEV_2010 WINDOW=FRONT.
DATASET ACTIVATE FEV_2010.
ALTER TYPE MOTIVO (a32).
DATASET ACTIVATE JAN_2010.
ADD FILES /FILE=*
/FILE='FEV_2010'.
EXECUTE.
SAVE OUTFILE='C:\Users\luizz\DADOS\DADOS_JAN_FEV_2010.sav'
/COMPRESSED.
Someone would know how to program a macro for this in SPSS?
Thank you,