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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

4 REPLIES 4
Shmuel
Garnet | Level 18

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;

Reeza
Super User

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. 

ballardw
Super User

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;

mjsommerville
Calcite | Level 5

A little confused about the question. But you can also add a new variable like this, using alter table and add. This would be in SAS, code is to add a new character variable, length 9, called staffID

 

proc sql; 

alter table work.sqlinsas 

 

add staffID char 9 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 47119 views
  • 2 likes
  • 5 in conversation