BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alexgonzalez
Quartz | Level 8

Hello,

Suppose I want to concatenate a letter at the end of a numeric variable. I run the follow code and it works.

Example 1:

data example1;

   set example1 (keep=p18);

p18 =round (p18,.1);

 

z=catx('',p18,.E);

run;

It returns, for example, a value character value z =12.2E.

 

When I apply the same CATX function within an array, it does not work. The code used in show below.

 

Example 2:

data example2;

   set example2 (keep= mean mean_SE mean_CV

                       p1    p1_SE   p1_CV

                       p18  p18_SE  p18_CV);

 

array  E {3}   mean    p1     p18;

array NE {3} $ mean    p1     p18;

array SE {3}   mean_SE p1_SE  p18_SE;

array CV {3}   mean_CV p1_CV  p18_CV;

 

  do i = 1 to 3;

 

    if 16.6 < CV[i] < 33.3 then do;

            NE[i]  = catx('',E[i],.E); 

            SE[i] = .;

    end;

 

   end;

drop i;

run;

 

Can anyone please advice? It would be great if you can also suggest me how to round all the values for a numeric array.

Thanks a lot,

AG.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Example 1 works because you assign the character string with the suffix to a new variable.

Example 2 fails because you are trying to replace existing variables. You need to supply new variable names in the NE array.

View solution in original post

4 REPLIES 4
Astounding
PROC Star
Example 1 works because you assign the character string with the suffix to a new variable.

Example 2 fails because you are trying to replace existing variables. You need to supply new variable names in the NE array.
alexgonzalez
Quartz | Level 8
That's great, I did it and it worked.
Thanks a lot.
Tom
Super User Tom
Super User

Why are you using CATX() if you don't actually have any string that you want inserted between the values? Use CATS() instead.

 

You need to make up your mind whether the variables MEAN, P1 and P18 are numbers or character strings. They cannot be both at the same time.

 

Why not make NEW variables for the new values?

array E mean p1 p18;
array NE $13 mean_e p1_e p18_e;

Note you don't need to tell the ARRAY statement how many variables the array references when you have listed all of the variables explicitly in the array statement already.

 

 

alexgonzalez
Quartz | Level 8
Thanks a lot Tom, that worked.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1362 views
  • 2 likes
  • 3 in conversation