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.
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.
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.
Post your code and log.
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?
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 .
@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.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.