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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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