Help using Base SAS procedures

How to convert all numeric variables into characters and concatenate the values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

How to convert all numeric variables into characters and concatenate the values

I have a dataset with some unknow number of numeric variables (>10) and character variables (>20).

The question is how to convert all the numeric values into character values, and then contatenate these values into a single string.

Thanks very much.


Accepted Solutions
Solution
‎11-18-2011 09:04 AM
Regular Contributor
Posts: 184

Re: How to convert all numeric variables into characters and concatenate the values

The ARRAY isn't necessary. Instead:

  length newv $ 200 ;

  newv=catx(' ',of _numeric_) ;

art297 wrote:

data have;

  do i=10 to 11;

   n1=i;

   n2=i+8;

   n3=i+5;

   n4=i+1;

   n5=2*i;

    output;

  end;

run;

data want;

  set have;

  array nums(*) _numeric_;

  newv=catx(' ',of nums(*));

run;

View solution in original post


All Replies
Super User
Posts: 5,424

How to convert all numeric variables into characters and concatenate the values

You could put all the variables into an array using the _numeric_ key-word.

Concatenation can you do in a do loop using the dim() function.

/Linus

Data never sleeps
Super Contributor
Posts: 1,636

Re: How to convert all numeric variables into characters and concatenate the values

data have(drop=i);

do i=10 to 11;

n1=i;

n2=i+8;

n3=i+5;

n4=i+1;

n5=2*i;

output;

end;

run;

data want;

length new $ 200;

  set have;

  array _num(*) _numeric_;

        new=catt(of _num(*));

run;

PROC Star
Posts: 7,467

How to convert all numeric variables into characters and concatenate the values

data have;

  do i=10 to 11;

   n1=i;

   n2=i+8;

   n3=i+5;

   n4=i+1;

   n5=2*i;

    output;

  end;

run;

data want;

  set have;

  array nums(*) _numeric_;

  newv=catx(' ',of nums(*));

run;

Solution
‎11-18-2011 09:04 AM
Regular Contributor
Posts: 184

Re: How to convert all numeric variables into characters and concatenate the values

The ARRAY isn't necessary. Instead:

  length newv $ 200 ;

  newv=catx(' ',of _numeric_) ;

art297 wrote:

data have;

  do i=10 to 11;

   n1=i;

   n2=i+8;

   n3=i+5;

   n4=i+1;

   n5=2*i;

    output;

  end;

run;

data want;

  set have;

  array nums(*) _numeric_;

  newv=catx(' ',of nums(*));

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 166 views
  • 6 likes
  • 5 in conversation