I am trying to concatenate several variables into one variable called "result" that is numeric. The variables are all numeric with the format BEST12. and the informat 12. When I run the code below, I get the following error:
659 DATA want; set have;
660 result = cat(of v1-v5);
661 put result BEST12.;
-------
48
ERROR 48-59: The format $BEST was not found or could not be loaded.
662 RUN;
Here is my code, please help me figure out why I am getting this error.
DATA have;
INPUT v1 v2 v3 v4 v5;
DATALINES;
0 1 0 1 1
0 0 0 0 0
1 1 0 1 1
1 1 1 1 1
1 0 0 0 1
0 1 1 0 0
1 1 1 0 1
0 0 1 1 0
;
RUN;
DATA want; set have;
result = cat(of v1-v5);
put result BEST12.;
RUN;
The reason I want the numeric format for the "result" variable is for analysis purposes, to be able to run a PROC FREQ on this variable.
CAT() is the concatenate function and returns a character variable.
You can either convert it back to numeric and apply a Z5 format or you can instead use some math to make a new variable v1*10000+ v2*1000 etc.
@lady8506 wrote:
I am trying to concatenate several variables into one variable called "result" that is numeric. The variables are all numeric with the format BEST12. and the informat 12. When I run the code below, I get the following error:
659 DATA want; set have;
660 result = cat(of v1-v5);
661 put result BEST12.;
-------
48
ERROR 48-59: The format $BEST was not found or could not be loaded.662 RUN;
Here is my code, please help me figure out why I am getting this error.
DATA have; INPUT v1 v2 v3 v4 v5; DATALINES; 0 1 0 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 1 1 0 ; RUN; DATA want; set have; result = cat(of v1-v5); put result BEST12.; RUN;
The reason I want the numeric format for the "result" variable is for analysis purposes, to be able to run a PROC FREQ on this variable.
CAT() is the concatenate function and returns a character variable.
You can either convert it back to numeric and apply a Z5 format or you can instead use some math to make a new variable v1*10000+ v2*1000 etc.
@lady8506 wrote:
I am trying to concatenate several variables into one variable called "result" that is numeric. The variables are all numeric with the format BEST12. and the informat 12. When I run the code below, I get the following error:
659 DATA want; set have;
660 result = cat(of v1-v5);
661 put result BEST12.;
-------
48
ERROR 48-59: The format $BEST was not found or could not be loaded.662 RUN;
Here is my code, please help me figure out why I am getting this error.
DATA have; INPUT v1 v2 v3 v4 v5; DATALINES; 0 1 0 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 0 0 1 1 0 ; RUN; DATA want; set have; result = cat(of v1-v5); put result BEST12.; RUN;
The reason I want the numeric format for the "result" variable is for analysis purposes, to be able to run a PROC FREQ on this variable.
I was finally able to solve my problem using a suggestion from Reeza that I convert it back to numeric with a Z5 format. Here is the code I used.
DATA want; set have;
format result2 Z5.;
result = cat(of v1-v5);
put result $char.;
result2 = result;
RUN;
That probably leaves a conversion note in your log that you don't want, otherwise it's hard to detect a real error from a conversion note.
DATA want; set have;
result = input(cat(of v1-v5), 8.);
format result z5.;
RUN;
Make it numeric:
DATA want; set have;
result = input(cat(of v1-v5),best.);
put result BEST12.;
RUN;
@lady8506 wrote:
The reason I want the numeric format for the "result" variable is for analysis purposes, to be able to run a PROC FREQ on this variable.
PROC FREQ works with both character and numeric variables. Do you still see an advantage of having a numeric variable result?
@FreelanceReinh wrote:
@lady8506 wrote:
The reason I want the numeric format for the "result" variable is for analysis purposes, to be able to run a PROC FREQ on this variable.
PROC FREQ works with both character and numeric variables. Do you still see an advantage of having a numeric variable result?
I would suspect the OP only wants a single table instead of five tables and shouldn't care too much.
But Proc tabulate would work with the 5 variables:
proc tabulate data=have;
class v1-v5;
table v1*v2*v3*v4*v5,
n colpctn
;
run;
Though the appearance may not be "ideal"
Probably where the LIST option from PROC FREQ comes in handy?
data random;
array v(*) v1-v5;
do i=1 to 100;
do j=1 to 5;
v(j) = rand('bernoulli', 0.3);
end;
output;
end;
run;
proc freq data=random;
table v1*v2*v3*v4*v5 / list out=want;
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.