DATA Step, Macro, Functions and more

Why is this macro dont working?

Reply
Occasional Contributor
Posts: 7

Why is this macro dont working?

What im trying to do is load some txt plain.

%let DIR_IN_BASE=I:\SGEE\SGEE\Jorge\Proyecto\ENTRADA; 
%let DIR_OUT_BASE=I:\SGEE\SGEE\Jorge\Proyecto\SALIDA;

%let RUT_IN=&DIR_IN_BASE;

%let FILE_TIT_IN=fp;
%let FILE_TIT_OUT=fichero_fp_salida;

%let CURSO=17;

**nombre variables;
%let PERIODO_REF_ACT = cursoacademico;
%let COD_TIPO_DOCU = tipodocumento;
%let ID_DOCUMENTO = documento;
%let COD_SEXO = sexo;
%let COD_GRUPO_EDAD = grupoedad;
%let COD_TIPO_ACT = curso;
%let COD_CENTRO = centro;
%let COD_SITUAC_SOCIO = situacionsocial;
%let COD_SITUAC_ACTIV = situacionlaboral;
%let FECHA_ENTR_ACT = entrada;
%let FECHA_SAL_ACT = salida;

libname fp_out "&DIR_OUT_BASE";

%macro mImport_txt(FILE_IN=,FILE_OUT=);
DATA &FILE_OUT; 
INFILE &FILE_IN pad lrecl=5000;
INPUT   
		@1 &cursoacademico 4.
		@5 &tipodocumento 1.
		@6 &documento $ 9.
		@15 &sexo 1.
		@16 &grupoedad 2.
		@18 &curso 3.
		@21 &centro 8.
		@29 &situacionsocial 1.
		@30 &situacionlaboral 1.
		@31 &entrada $ 8.
		@39 &salida $ 8.;
RUN;
%mend mImport_txt;

%mImport_txt(FILE_IN="&RUT_IN.&FILE_TIT_IN..txt",FILE_OUT=&FILE_TIT_IN._&CURSO);

And the error is this

 

15         %mImport_txt(FILE_IN="&RUT_IN.&FILE_TIT_IN..txt",FILE_OUT=&FILE_TIT_IN._&CURSO);
22: LINE y COLUMN no se pueden determinar.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN 
              where the error has occurred.
ERROR 22-322: Expecting a name.  
WARNING: Apparent symbolic reference CURSOACADEMICO not resolved.
22: LINE y COLUMN no se pueden determinar.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN 
              where the error has occurred.
ERROR 22-322: Expecting a name.  
WARNING: Apparent symbolic reference TIPODOCUMENTO not resolved.
22: LINE y COLUMN no se pueden determinar.

thanks for all!

Super User
Posts: 9,611

Re: Why is this macro dont working?

When you do this:

%let PERIODO_REF_ACT = cursoacademico;

you set the macro variable PERIODO_REF_ACT to the value cursoacademico.

When you do this:

INPUT   
		@1 &cursoacademico 4.

you are trying to reference the macro variable cursoacademico, which does not exist.

 

Why do you want to use different variable (column) names, when the files have apparently the same structure?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
SAS Employee
Posts: 5

Re: Why is this macro dont working?

Hi,

 

The reason for the errors is because macro variables like cursoacademico are not set.  There are two possibilities...

 

Either your %LETs were wrong, so where you had...

 

   %let PERIODO_REF_ACT = cursoacademico;

 

You should have had

 

   %let cursoacademico = PERIODO_REF_ACT ;

 

Or your input statement used the wrong macro variable name, so

 

   @1 &cursoacademico 4.

 

should have been

 

   @1 &PERIODO_REF_ACT 4.

 

Once you know which you really need you can change all the others in the same way.

 

Mark

Super User
Super User
Posts: 9,227

Re: Why is this macro dont working?

Why do you have all the macro code?  As I mention in your other post.  To import a file you do a simple:

data want;
  infile...;
  informat...;
  format...;
  length...;
  input...;
run;

You will see from the above there is no % this or & that, just plain simple Base SAS code.  This is the place to start (and in 99% of cases stop).  Do not get into the habbit of using macro just for the sake of using, it does not add anything to the code and makes it far less reliable and harder to maintain, especially when you consider the code presented has no need for the macro whatsoever.

Frequent Contributor
Posts: 113

Re: Why is this macro dont working?

I think it's because of this

%let DIR_IN_BASE=I:\SGEE\SGEE\Jorge\Proyecto\ENTRADA;

change it to this

%let DIR_IN_BASE=I:\SGEE\SGEE\Jorge\Proyecto\ENTRADA\;

 

Ask a Question
Discussion stats
  • 4 replies
  • 88 views
  • 2 likes
  • 5 in conversation