Help using Base SAS procedures

Numeric Format Error

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Numeric Format Error

[ Edited ]

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.  


Accepted Solutions
Solution
4 weeks ago
Super User
Posts: 23,752

Re: Numeric Format Error

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


All Replies
Solution
4 weeks ago
Super User
Posts: 23,752

Re: Numeric Format Error

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.  


 

Contributor
Posts: 37

Re: Numeric Format Error

[ Edited ]

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;
Super User
Posts: 23,752

Re: Numeric Format Error

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;
Super User
Posts: 10,259

Re: Numeric Format Error

Make it numeric:

DATA want; set have;
result = input(cat(of v1-v5),best.);
put result BEST12.;
RUN;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Trusted Advisor
Posts: 1,252

Re: Numeric Format Error


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

Super User
Posts: 13,563

Re: Numeric Format Error

Posted in reply to FreelanceReinhard

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


@FreelanceReinhard

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"

Super User
Posts: 23,752

Re: Numeric Format Error

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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