Hi,
Is it possible to use Proc format value in Proc SQL select step?. Below is my code
Proc Sql;
Create table test as
select
employee_Id,
put(salary, $sal_rng.) as Sal_rng
from emp_tbl
;
Quit;
I am getting error messsage as "The format $sal_rng was not found or could not be loaded". The same format works fine if i use it in a datastep.
Thanks,
/*I don't have problem to run the code below which is similar to your code:*/
proc format;
value $sex
a='male'
b='female';
run;
data have;
input id sex$;
cards;
1 a
2 b
3 b
4 a
;
proc sql;
create table want as
select id,put(sex,$sex.) as gender
from have;
quit;
proc print;run;
Obs id gender
1 1 male
2 2 female
3 3 female
4 4 male
Linlin
/*I don't have problem to run the code below which is similar to your code:*/
proc format;
value $sex
a='male'
b='female';
run;
data have;
input id sex$;
cards;
1 a
2 b
3 b
4 a
;
proc sql;
create table want as
select id,put(sex,$sex.) as gender
from have;
quit;
proc print;run;
Obs id gender
1 1 male
2 2 female
3 3 female
4 4 male
Linlin
It worked. Thanks!!
I'm confused! Glad you were able to solve your problem but, unless I've missed something, future readers won't know what the problem or solution was. Linlin showed that your original code would work if salary was a character variable, but you had indicated that the code didn't work.
Looks to me like salary is a numeric variable and that you are getting the error because you are trying to apply a character format.
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 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.
Ready to level-up your skills? Choose your own adventure.