Bonsoir,
j'ai réussi à mettre en oeuvre la méthode
1 2 3 4 5 6 7 8
| %macro verif_num_char(string);
DATA _NULL_;
var=input("&string" ,?? COMMA8.);
IF var=. then call symput('type','CHAR');
else call symput('type','NUM');
run;
%put &type;
%mend; |
exposée dans ce sujet
Les calculs engendrés par cette méthode m'apparaissent néanmoins très longs car le data _null_ est exécuté pour un grand nombre de variables et plusieurs milliers d'enregistrements.
J'essaie donc d'utiliser la macro suivante :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| %Macro DataTyp_Numeric(MyVarIn) / store;
%Global Flag;
%local stVal;
/* Par convention, l'informat d'une valeur vide est correct */
%If &MyVarIn= %Then %Let Flag=1;
/* Cas d'une valeur non vide */
%If &MyVarIn ne %Then
%Do;
/* Cas d'une valeur constituée de blancs */
/* Strip enlève les blancs aux extrêmités */
%let stVal=%sysfunc(Strip(&MyVarIn));
/* Par convention, l'informat d'une valeur composée de blancs est correct */
%IF %LENGTH(&stVal)=0 %THEN %Let Flag=1;
%IF %LENGTH(&stVal)>0 %THEN %DO;
%let Flag=0;
%Local j;
/* On ôte de MyvarIn passé en paramètre les caractères constitutifs d'un nombre */
/* i.e. espace, chiffres, virgule, point, +, - */
/* Ensuite on compte le nombre de caractères restants */
%let j = %sysfunc(compress(&myvarin.," 0123456789.,+-"));
%IF %LENGTH(&j) eq 0 %THEN %let Flag=1;
%END;
%End;
%Mend; |
que j'appelle grâce à un call execute dans une étape data :
If code_ ne &MyValueVide then do;CALL EXECUTE ('%DataTyp_Numeric('|| put(code, 3.) ||')'); %If &Flag ne 1 %Then %Do; code_=&MyFormatNok; %end; %Else %do; code_=&MyFormatOk; %end; end;
Cet appel me génère le message suivant :
ERREUR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &MyVarIn=
ERREUR: The macro DATATYP_NUMERIC will stop executing.
J'ai essayé différentes syntaxes :
1 2 3
| %STR(%')&MyString%STR(%')
'&MyString'
%eval(&MyString) |
Avec %eval le message est :
1 2
| ERREUR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: 1.00 |
sans succès.
Je tourne en rond pour essayer de trouver une syntaxe correcte.
Si quelqu'un a une idée ça me dépannerait bien.
Merci
Partager