PUT to create new variable from old variable in PROC SQL?

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

PUT to create new variable from old variable in PROC SQL?

I am to

Use seed_ as the label in your format. Note, labels are text but the seed_field is

numeric. Use a put function to convert the number to a text. Assume the number will

be in the 2. format.

libname bask 'C://users/zscott1/forsas';

proc sql;

create table changed as

select Team as Start,seed_ as Label

from bask.mbb04

group by Start;

quit;

I've tried

proc sql;

alter table changed

add  Fmtname char;

select Label as put(Label_,$2.)

from changed;

quit;

and

data _null_;

        set changed;

        Labels =put(Label,2.);

     run;

Neither are creating variables for me that work and are created as character variables from the numeric variable 'label';

How will I do this?


Accepted Solutions
Solution
‎04-28-2014 04:54 AM
Super User
Super User
Posts: 7,942

Re: PUT to create new variable from old variable in PROC SQL?

Yes, to use your code:

proc sql;

  create table changed as

  select Team as Start,

             put(seed_,2.) as Label

  from bask.mbb04

  group by Start;

quit;

View solution in original post


All Replies
Super User
Posts: 5,426

Re: PUT to create new variable from old variable in PROC SQL?

You need to study the basics of assignments, both in SQL and the data step. Syntax in SQL is:

select expression as colname

You put it other way which clearly doesn't work.

When putting a numerical variable, you use a numeric format, not a char format.

Data never sleeps
Solution
‎04-28-2014 04:54 AM
Super User
Super User
Posts: 7,942

Re: PUT to create new variable from old variable in PROC SQL?

Yes, to use your code:

proc sql;

  create table changed as

  select Team as Start,

             put(seed_,2.) as Label

  from bask.mbb04

  group by Start;

quit;

Contributor
Posts: 30

Re: PUT to create new variable from old variable in PROC SQL?

Thank you.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 236 views
  • 1 like
  • 3 in conversation