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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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