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-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
  • 3 replies
  • 776 views
  • 0 likes
  • 3 in conversation