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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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