DATA Step, Macro, Functions and more

Comparison issue within a macro progrm

Reply
Contributor
Posts: 36

Comparison issue within a macro progrm

Hello,
the following comparison is always false within the %Tmt macro program :

[pre]%If &stMois eq &MyMois and &stAnnee eq &MyAnnee and &stPeriode eq &MyPeriode and %eval(&lFicOk) eq 1 %Then %Do;[/pre]

Though I see 2 records in the listeFichiers table for which the clause should be true.

If someone has an idea it would be great !

phil

[pre]%Macro CopieTable(MyTableSource, MyTableDest);
data &MyTableDest;
set &MyTableSource;
run;
%Mend;

%Global stFichierSource;
%Global stRep;
%Global stPrefD;

%Global stMois;
%Global stAnnee;
%Global stPeriode;
%Global lFicOk;

%Macro Tmt(MyMois,MyAnnee,MyPeriode,MyTableDest);

Proc Sql;
Create table listeFichiers as select distinct Fichier, Mois, Annee, Periode, FicOk, NBENREG
From AppliCft.Ficrecusdet;
Quit;

data _null_;
set listeFichiers;
PrefD="D_";
PrefC="C_";
Post="A_TRAITER\";
RepIn="C:\FichiersAImporter\";

IF Periode='A' then Rep=catx('\',RepIn,Annee,Mois,'ANNUEL',Post);
IF Periode='M' then Rep=catx('\',RepIn,Annee,Mois,'MENSUEL',Post);

Call SymputX('stMois',Mois);
Call SymputX('stAnnee',Annee);
Call SymputX('stPeriode',Periode);
Call SymputX('lFicOk',FicOk);

%put &stMois &MyMois;
%put &stAnnee &MyAnnee;
%put &stPeriode &MyPeriode;
%put &lFicOk;

%If &stMois eq &MyMois and &stAnnee eq &MyAnnee and &stPeriode eq &MyPeriode and &lFicOk eq 1 %Then %Do;

Call SymputX('stPrefD',PrefD);

Call SymputX('stRep',Rep);
libname L "&stRep";

Call SymputX('stFichierSource',Fichier);

/* Si &MyTableDest existe déjà */
%if %sysfunc(exist(&MyTableDest)) eq 1 %then %CopieTable(L.&stPrefD&stFichierSource &MyTableDest,&MyTableDest);

/* Sinon */
/* Si &MyTableDest existe déjà */
%if %sysfunc(exist(&MyTableDest)) eq 0 %then %CopieTable(L.&stPrefD&stFichierSource,&MyTableDest);
%End;
run;
%Mend;

/* Début du traitement */
%Tmt(12,2009,A,AppliCft.Agreg122009a);
[/pre]
Respected Advisor
Posts: 3,799

Re: Comparison issue within a macro progrm

When the %IF statement in question is executed the data step that is creating the variables used in that step has not executed. You will need to cause that data step to execute before the %IF statement is attempted.

You will also need to "re-think" the code within the %IF.
Contributor
Posts: 36

Re: Comparison issue within a macro progrm

Okay,
thanks
data _null_;

I should not use a macro program to perform this.
But I did non find a way to create the table in the [If Then] bloc inside the data step.

I think that I will create a blank table and delete its records at the begining of the process so that I don't have to test if the table exists.

phil
Ask a Question
Discussion stats
  • 2 replies
  • 131 views
  • 0 likes
  • 2 in conversation