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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.