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-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!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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