BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Andrew15
Fluorite | Level 6
data Karen_D2t1; 
set sashelp.cars;
 run; 

proc sort data=Karen_D2t1; 
by make type; 
run; 

proc means data=Karen_D2t1 mean; 
by make type; 
var horsepower; 
output out=a2(drop=_freq_ _type_) mean=MeanHP; 
run; 

proc means data=Karen_D2t1 mean; 
by make type;
 var invoice ; 
output out=a3(drop=_freq_ _type_) mean=MeanIN; 
run; 

proc means data=Karen_D2t1 mean;
 by make type;
 var weight; 
output out=a4(drop=_freq_ _type_) mean=MeanW; 
run; 

data a5; merge a2 a3 a4; run; 

proc transpose data=a5 out=a5t; 
var MeanHP; 
run; 

data a8; 
Length char1 $ 1500.; 
set a5t; 
char1=catx(", ", of col1-col29);
 run;

Hello. I Have i code below,in which i treied to create variable "char1" which will contain values of all variables from dataset a5t,separated by "," . And this works but i just need to get more flexible code which will work for any count of columns and not only 29 of them. Can you help me to find a solution? Would be thankful!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Thank you for providing fully working sample code. That always helps a lot. 

Just by looking at your code without even trying to understand what you want to achieve: It feels very much like there should be a simpler more direct way.

 

But to answer your actual question: Use the column modifier and the code will pick-up all variables that start with name col.

Patrick_0-1684065771527.png

 

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Thank you for providing fully working sample code. That always helps a lot. 

Just by looking at your code without even trying to understand what you want to achieve: It feels very much like there should be a simpler more direct way.

 

But to answer your actual question: Use the column modifier and the code will pick-up all variables that start with name col.

Patrick_0-1684065771527.png

 

Andrew15
Fluorite | Level 6
Thank you so much,i got desirable result!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 930 views
  • 1 like
  • 2 in conversation