Hello Experts,
My code in data _null_ is :
CALL SYMPUTX(COMPRESS('NOM_Mode_n1'),propcase(lb_lg_1));
CALL SYMPUTX(COMPRESS('NOM_Mode_n2'),propcase(lb_lg_2));
CALL SYMPUTX(COMPRESS('NOM_Mode_n3'),propcase(lb_lg_3));
CALL SYMPUTX(COMPRESS('NOM_Mode_n4'),propcase(lb_lg_4));
CALL SYMPUTX(COMPRESS('NOM_Mode_n5'),propcase(lb_lg_5));
CALL SYMPUTX(COMPRESS('NOM_Mode_n6'),propcase(lb_lg_6));
CALL SYMPUTX(COMPRESS('NOM_Mode_n7'),propcase(lb_lg_7));
CALL SYMPUTX(COMPRESS('NOM_Mode_n8'),propcase(lb_lg_8));
I would like to reduce the code with this line :
%do i=1 %to 8;
CALL SYMPUTX(COMPRESS('NOM_Mode_de_gest_n&i.'),propcase(lb_lg_gar_1));
%end;
But while running this code I have an error message:
ERROR: Symbolic variable name NOM_MODE_DE_GEST_N&I. must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('NOM_Mode_de_'[12 of 21 characters shown],' '[12 of 50 characters shown]) at line
486 column 10 is invalid.
Could you help me please to resolve this error ?
Thank you !
Use double quotes.
What's the purpose of the compress() function in above expression?
Since you are running a DATA step, you need to use a DO loop, not a %DO loop. For example,
array lb_lg_ {8};
do i=1 to 8;
call symputx('NOM_Mode_n' || put(i, 1.), propcase(lb_lg_{i}));
end;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.