Help using Base SAS procedures

How to put a list of variables between brackets?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to put a list of variables between brackets?

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


Accepted Solutions
Solution
‎02-15-2012 06:36 PM
PROC Star
Posts: 7,492

How to put a list of variables between brackets?

Posted in reply to Fontaines03

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


All Replies
PROC Star
Posts: 7,492

How to put a list of variables between brackets?

Posted in reply to Fontaines03

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?


Occasional Contributor
Posts: 5

How to put a list of variables between brackets?

&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.

Solution
‎02-15-2012 06:36 PM
PROC Star
Posts: 7,492

How to put a list of variables between brackets?

Posted in reply to Fontaines03

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;

Occasional Contributor
Posts: 5

How to put a list of variables between brackets?

I works !   Thanks a lot.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1168 views
  • 0 likes
  • 2 in conversation