BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

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 !

2 REPLIES 2
Patrick
Opal | Level 21

Use double quotes.

Patrick_1-1649017875827.png

What's the purpose of the compress() function in above expression?

Astounding
PROC Star

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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