BookmarkSubscribeRSS Feed
phil27
Calcite | Level 5
Hello,
In the following code, the macro-variables :
Annee, Mois, Periode and FicOk have no value affected at the first run of the code.

Annee, Mois, Periode are affected at the second run and FicOk at the third time.

How could I do to make the programme run at the first time ?

Thanks.


%Macro CreeTableMensuelle(MyTableRef, MyLibIn, MyTableOut, MyAnnee, MyMois, MyPeriode);
%Global PrefD;
%Global PrefC;
%Global PostRep;

%Global stRep;
%Global stFichier;

%Global Annee;
%Global Mois;
%Global Periode;
%Global FicOk;

%Global Nom;


/* Préfixe pour tables de données : Les tables s'appellent D_ suivi du nom du fichier d'origine */
%Let PrefD=D_;

/* Préfixe pour table de tests de contraintes */
%let prefC=C_;

/* PostFixe pour répertoire de tables à traiter (nom de la feuille de l'arborescence) */
%Let PostRep=A_TRAITER;

/* On parcourt la table MyTableRef */
Data _NULL_;
Set &MyTableRef;

/* Si l'enregistrement courant présente les bonnes condition alors on ajoute */
/* Le fichier qu'il désigne à MyTableOut */
Call SymputX('Annee',input(Annee,best.));
Call SymputX('Mois',input(Mois,best.));
Call SymputX('Periode',Periode);
Call SymputX('FicOk',input(FicOk,best.));

%If &Annee eq &MyAnnee and &Mois eq &MyMois and &Periode eq &MyPeriode and &FicOk eq 1 %Then %Do;

/* Constitution du répertoire physique où se situe la table */
/* des données à intégrer à la table mensuelle des données */
%If &MyPeriode eq A %Then %Let stRep=&MyLibIn.\&MyAnnee.\&MyMois.\ANNUEL;
%If &MyPeriode eq M %Then %Let stRep=&MyLibIn.\&MyAnnee.\&MyMois.\MENSUEL;

Libname LibSrc "&stRep.\&PostRep";
%put &stRep.\&PostRep;

/* Nom de la table à intégrer */
Call SymputX('Nom',Fichier);
%Let stFichier=&PrefD.&Nom;
%put MyTableRef = &MyTableRef - stFichier = &stFichier;

/* Ajout de la table à MyTableOut */
%IntegreTable(LibSrc.&StFichier,&MyTableOut);


/* Constitution du nom de la table des tests à intégrer à la table mensuelle des tests */

%End;

Run;
%Mend;
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS program you shared is invoking a SAS macro which you have not provided in your post, that is IntegreTabl.

Also, you are mixing SAS macro language and DATA step CALL SYMPUTX - the CALL function creates SAS global macro variables but it occurs during DATA step execution and not SAS macro compilation, normally.

And, you have a SAS LIBNAME statement in the middle of what appears to be a DATA step execution.

You must create SAS global macro variables using %LET statements, before the macro CreeTableMensuelle is executed.

Below, you will find a suggested SAS support website search argument, which will generate some links for your review and reading on this subject-matter.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

macro variable focus symput global site:sas.com
RickM
Fluorite | Level 6
I am not a macro expert but I believe the problem might be that when you use "call symputx" you cannot use the same macro within the data step. You might need to use a couple of data _NULL_ steps and make sure you end them with run;
phil27
Calcite | Level 5
Thank you for your answers.
I will have a look at this.

Phil.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 996 views
  • 0 likes
  • 3 in conversation