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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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