Why is this code failing?

Reply
New Contributor
Posts: 3

Why is this code failing?

[ Edited ]

I defined a format using proc format, and then try to use it in proc sql, but an error message keeps coming out and I don't know what I did wrong. Hope someone can help me with it, thanks a lot!

 

17   proc format library=Project;
18   value $ range
19   810-high = '810+'
20   790-809 = '790-809'
21   770-789 = '770-789'
22   750-769 = '750-769'
23   730-749 = '730-749'
24   710-729 = '710-729'
25   690-709 = '690-709'
26   670-689 = '670-689'
27   650-669 = '650-669'
28   630-649 = '630-649'
29   low-629 = '<630'
30   other = 'Null or Zero';
31   run;
32   OPTIONS FMTSEARCH=(Project);
33   run;
34
35   proc sql;
36   create table project.n1 as
37   select score,  put(Score,$range.) as range
38   from
39   project.student;

40  quit;

The message is like:
error: character format $range in PUT function requires a character argument.

Super User
Posts: 19,157

Re: Why this code is failing?

This isn't a character format, its a numeric format - applied to numbers.

 

Remove the dollar sign from PROC FORMAT VALUE statement and the PUT function.

New Contributor
Posts: 3

Re: Why this code is failing?

Thanks for replying, I did what you said but it returned another message like ERROR: The format $RANGE was not found or could not be loaded. I did remove the dollar sign from value statement. 

Super User
Posts: 19,157

Re: Why this code is failing?

Post your code and log. 

New Contributor
Posts: 3

Re: Why this code is failing?

It worked after all, thanks. But the problem is the format 'range' has to be a character format according to the requirement, so I wonder if there is a way to do it? 

Trusted Advisor
Posts: 1,470

Re: Why this code is failing?

[ Edited ]

In your sql code you used the format in "put(Score,$range.) as range"

 

What type is the score variable ? If sas asks for $format it means that the variable is a alphanumeric,

then use:  put(input(score, best 5.),range.) as range and remove the $ from the value statment .

Super User
Posts: 7,435

Re: Why is this code failing?

[ Edited ]

xiy513 wrote:

It worked after all, thanks. But the problem is the format 'range' has to be a character format according to the requirement, so I wonder if there is a way to do it? 


The result of the put() function is always of type character.

 

To really illustrate your issue, you need to supply example data; do so in a data step.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 6 replies
  • 199 views
  • 0 likes
  • 4 in conversation