BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vicky07
Quartz | Level 8

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

/*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

View solution in original post

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

/*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

vicky07
Quartz | Level 8

It worked. Thanks!!

art297
Opal | Level 21

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.

art297
Opal | Level 21

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.

SAS Innovate 2025: Register Now

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 10914 views
  • 2 likes
  • 3 in conversation