Help using Base SAS procedures

creating new columns in proc sql

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

creating new columns in proc sql

Hello,

 

I am creating 3 tables using proc sql and I want to create a new column for each of them. I just know case when to create column based on different conditions. But here, I only want to create one to work like a lable: new column=secure the value would be Y

 

thank you.


Accepted Solutions
Solution
‎02-14-2017 03:55 PM
Trusted Advisor
Posts: 1,554

Re: creating new columns in proc sql

Posted in reply to septemberbulb

In case you want same value in all observations, do:

 

proc sql;

    create table want 

    as select *,

     'Y' as secure

     from have;

quit;

 

or use a datastep:

 

data want;

  set have;

      secure = 'Y';

run;

View solution in original post


All Replies
Solution
‎02-14-2017 03:55 PM
Trusted Advisor
Posts: 1,554

Re: creating new columns in proc sql

Posted in reply to septemberbulb

In case you want same value in all observations, do:

 

proc sql;

    create table want 

    as select *,

     'Y' as secure

     from have;

quit;

 

or use a datastep:

 

data want;

  set have;

      secure = 'Y';

run;

Super User
Posts: 19,770

Re: creating new columns in proc sql

Posted in reply to septemberbulb

Not 100% sure I understand your question but look into either:

 

COALESCE() to choose one field from the three that isnt' missing

 

or INDSNAME to identify the source data in a data step. 

Super User
Posts: 11,343

Re: creating new columns in proc sql

Posted in reply to septemberbulb

It may help to provide some example data of what one of the sets looks like and what the desired result.

 

If you want to create variable with the same value for everyrow the easiest is to have something like this in the Select clause:

 

"Y" as new_var

Example:

proc sql;

   create table work.new as

   select *, 'Y' as new_var

   from sashelp.class;

quit;

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 1107 views
  • 0 likes
  • 4 in conversation