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.
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;
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;
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.
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
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.
Hi Bruno and Amir,
Its working. Thanks for your valuable suggestions and time.
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;
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!
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.