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

Hi,

I need to add brackets for a list of numerical variables. It seems that the concatenation doesn't work in an ARRAY statement.

This kind of data step doesn' work:

    data temp2;

                set temp1;

                array A(*) cat1-cat&N_cat;

                array B(*) &level._se1-&level._se&N_cat;

                do j=1 to dim(A);

                        B(j)=cats('(',A(j),')');

                end;

     run;

Because the number of variables to adapt can change, I thought to use an array statement.

Maybe with a proc format ?

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Then, how about?:

%let N=3;

data temp2 (drop=j);

  set temp1;

  array A(*) cat1-cat&N.;

  array B(&N.) $;

  do j=1 to &N.;

    B(j)=cats('(',A(j),')');

  end;

run;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

An example dataset would help people to respond, as well as your macro variable assignments.

Also, do the variables &level._se1-&level._se&N_cat

exist or are they new variables that you are trying to create?


Fontaines03
Calcite | Level 5

&level._se1-&level._se&N_cat are new variables.

&N_cat is a number which changes.

For example;

data temp1;

     input num cat1 cat2 cat3;

     datalines;

     1 3.35 5.36 9.25

     2 5.32 1.20 1.25

     ;

run;

I would like to put cat1 cat2 cat3 between brackets.

art297
Opal | Level 21

Then, how about?:

%let N=3;

data temp2 (drop=j);

  set temp1;

  array A(*) cat1-cat&N.;

  array B(&N.) $;

  do j=1 to &N.;

    B(j)=cats('(',A(j),')');

  end;

run;

Fontaines03
Calcite | Level 5

I works !   Thanks a lot.

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5835 views
  • 0 likes
  • 2 in conversation