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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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