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-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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