BookmarkSubscribeRSS Feed
phil27
Calcite | Level 5
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]
2 REPLIES 2
data_null__
Jade | Level 19
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.
phil27
Calcite | Level 5
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 732 views
  • 0 likes
  • 2 in conversation