BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7

So I have code where I want concat multiple(almost 30)  variable with different variable name 

For now am using ;

New = name||age||gender||sex||dob||addrees

 

Like this I have 30 var to concat 

 is there are any efficent way to do this 

 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If the variables are consecutive in the data set, so you want to concatenate all variables from firstvariablename to lastvariablename, use

newvariable=cat(of firstvariablename -- lastvariablename);

 

Other possibilities exist, depending on the location in the data set and whether variables are all numeric or all character. Do tell us more about this.

 

Also, I question how having all this information in a a very long text variable is a superior way to arrange your data compared to leaving them as individual variables. Why do you need this?

 

 

--
Paige Miller
Tom
Super User Tom
Super User

First is use one of the newer concatenation functions instead of the || operator.

Check out CATS() or CATX() as the most useful.  But there are others.

 

Once you are doing that you can then use variable lists in the function call.  That requires you to use the OF keyword.

string=catx('|',of name -- address);
string=catx('|',of _character_);
string=catx('|',of _all_);

Depending on the list and the dataset it might even be easier to use the DROP= dataset option to so that you only have to list the variables you don't want to include instead of the ones you do want.

data want;
  set have(drop=ignore_me);
  length string $200;
  string = catx('|',of _all_);
  set have;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 476 views
  • 0 likes
  • 3 in conversation