Help using Base SAS procedures

proc format value in proc SQL

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

proc format value in proc SQL

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,


Accepted Solutions
Solution
‎03-17-2012 11:25 PM
Super Contributor
Posts: 1,636

Re: proc format value in proc SQL

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


All Replies
Solution
‎03-17-2012 11:25 PM
Super Contributor
Posts: 1,636

Re: proc format value in proc SQL

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

Contributor
Posts: 71

Re: proc format value in proc SQL

It worked. Thanks!!

PROC Star
Posts: 7,467

Re: proc format value in proc SQL

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.

PROC Star
Posts: 7,467

Re: proc format value in proc SQL

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2367 views
  • 1 like
  • 3 in conversation