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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 750 views
  • 0 likes
  • 2 in conversation