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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Howles
Quartz | Level 8

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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
Linlin
Lapis Lazuli | Level 10

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;

art297
Opal | Level 21

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;

Howles
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1346 views
  • 6 likes
  • 5 in conversation