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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.