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

Hi,

I have dataset X with variables COL1 TO COLN....

I wanted to create new varaible to concatenate all collumns sepeareted by delimiter..... COLN coule be col20 or col25...so it has to be generalised for all col starting with COL.... I TRIED THIS WAY BUT NOT WORKING....

data _null_;

   separator='%%$%%';

   col1='The Olympic  ';

   col2='   Arts Festival ';

   col3='   includes works by ';

   col4='Dale Chihuly.';

   result=catx(separator,col:);

   put result $char.;

run;

.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data _null_;

   separator='%%$%%';

   col1='The Olympic  ';

   col2='   Arts Festival ';

   col3='   includes works by ';

   col4='Dale Chihuly.';

   result=catx(separator,of col:);

   put result $char.;

run;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi, that seems to be an example from the help page.  Anyways, use the of colx-coly.  Note it will trim your data and hence lose the spaces.

data _null_;

   col1='The Olympic  ';

   col2='   Arts Festival ';

   col3='   includes works by ';

   col4='Dale Chihuly.';

   result=cat(of col1-col4);

   put result $char.;

run;

If you need the $ then put it into your strings.

rakeshvvv
Quartz | Level 8

Hi,

I want a generalised solution as there is chance that new collumns(col 5 col6 col7) will be added to the dataset.... I want write in such a way that it would concatenalte all columns starting with name COL so that in case new collumns are added in near future....

Reeza
Super User

Are the variables already defined in the dataset or are you creating them?

If they're already defined you can try:

data want;

set have;

array col(*) col:;

result=catx(",", of col(*));

run;

stat_sas
Ammonite | Level 13

data _null_;

   separator='%%$%%';

   col1='The Olympic  ';

   col2='   Arts Festival ';

   col3='   includes works by ';

   col4='Dale Chihuly.';

   result=catx(separator,of col:);

   put result $char.;

run;

rakeshvvv
Quartz | Level 8

Thanks... This is what iw as looking for......

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
  • 5 replies
  • 7885 views
  • 4 likes
  • 4 in conversation