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

Hi,

I'm stuck while using CATX function.

I have thirty string variable(COL1 to COL30) and i want to join this all variable separeated by comma by using CATX. It doesnt working.

Is there is any other way to do this.

Your little help may be great help.

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

Hi,

 

Have you tried something like:

 

data _null_;
  col1='column 1';
  col2='column 2';
  col3='column 3';
  result=catx(',',of col1-col3);
  put result=;
run;

which for me gives:

 

result=column 1,column 2,column 3

 

If this does not work for you please post your code, what you expect and the log showing the error.

 

Also from @BrunoMueller:

 You can make use of variable lists in the CATX function, see also sample below using an array:

 

data want;
  length colString $ 120; 
  array myVars{30} $ 4 col1 - col30;
  nChar = rank("A");
  do i = 1 to dim(myVars);
    myVars{i} = byte(nChar);
    nChar + 1; 
  end; 

  colString = catx(",", OF myVars{*});
run;

View solution in original post

6 REPLIES 6
Amir
PROC Star

Hi,

 

Have you tried something like:

 

data _null_;
  col1='column 1';
  col2='column 2';
  col3='column 3';
  result=catx(',',of col1-col3);
  put result=;
run;

which for me gives:

 

result=column 1,column 2,column 3

 

If this does not work for you please post your code, what you expect and the log showing the error.

 

Also from @BrunoMueller:

 You can make use of variable lists in the CATX function, see also sample below using an array:

 

data want;
  length colString $ 120; 
  array myVars{30} $ 4 col1 - col30;
  nChar = rank("A");
  do i = 1 to dim(myVars);
    myVars{i} = byte(nChar);
    nChar + 1; 
  end; 

  colString = catx(",", OF myVars{*});
run;
SureshPadwal
Fluorite | Level 6

Hi Amir,

 

I have data like this with missing values. variables are character.

Col1 col2 col3 col4….col28

3 . 7 8….25

2 6 . 11….28

;

 

I want

Col1 col2 col3 col4….col28 result

3 4 7 8….25  3,4,7,8,…,25

2 6 9 11….28 2,6,9,11,….28

 

I have written:

data d3;
   length result $ 50;
   SP=',';
   result =catx(SP, of col1-col28);
run;

 

LOG is:

 

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      19:16   19:21  
NOTE: Invalid numeric data, COL5='           1*           6' , at line 19 column 21.

Hope this clear.

BrunoMueller
SAS Super FREQ

the Note

NOTE: Character values have been converted to numeric values at the places given by:

      (Line):(Column).

      19:16   19:21  

NOTE: Invalid numeric data, COL5='           1*           6' , at line 19 column 21.

Indicates that char values have been converted to numeric values, they are not coming from the CATX function

Amir
PROC Star

Hi,

Thanks for posting what you have. You shown some missing data, but you haven't said what result you want if the data is missing.

The data step does not seem complete as there is no input data specified, either through a set statement, or infile statement, or by some other means.

One of the log messages:

NOTE: Invalid numeric data, COL5='           1*           6' , at line 19 column 21.

shows data "1*           6'", are you expecting this kind of data too? Are you trying to perform maths on the character data?

I think we still need to be shown a clearer picture of what you have. Try posting a sample data step which we can run that shows what the problem is.

Regards,

Amir.

SureshPadwal
Fluorite | Level 6

Hi Bruno and Amir,

Its working. Thanks for your valuable suggestions and time.

BrunoMueller
SAS Super FREQ

Hi as Amir mentioned you can make use of variable lists in the CATX function, see also sample below using an array:

 

data want;
  length colString $ 120; 
  array myVars{30} $ 4 col1 - col30;
  nChar = rank("A");
  do i = 1 to dim(myVars);
    myVars{i} = byte(nChar);
    nChar + 1; 
  end; 

  colString = catx(",", OF myVars{*});
run;

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!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 6 replies
  • 48046 views
  • 2 likes
  • 3 in conversation