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

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.  

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.  


 

View solution in original post

7 REPLIES 7
Reeza
Super User

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.  


 

lady8506
Quartz | Level 8

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;
Reeza
Super User

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;
FreelanceReinh
Jade | Level 19

@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?

ballardw
Super User

@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?


@FreelanceReinh

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"

Reeza
Super User

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3262 views
  • 4 likes
  • 5 in conversation