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

Hi everyone,
I need help for this case :

I have a dataset DATA with columns A, B and C

I want to create a new column D = A + C + G

 

G does not exist in DATA, thus it will create blank for D. But is there a way to set non existing column (G) default values to 0 and then D will be equal to A + C ?

 

Thank you,

Gluttony

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The SUM() statement will ignore missing values.

The SUM operator (+) will not ignore missing values and sets everything to missing when it's blank. 

 

d_operator = a+c+g;
d_statement= sum(a, c, g);

@Gluttony wrote:

Hi everyone,
I need help for this case :

I have a dataset DATA with columns A, B and C

I want to create a new column D = A + C + G

 

G does not exist in DATA, thus it will create blank for D. But is there a way to set non existing column (G) default values to 0 and then D will be equal to A + C ?

 

Thank you,

Gluttony


 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@Gluttony wrote:

Hi everyone,
I need help for this case :

I have a dataset DATA with columns A, B and C

I want to create a new column D = A + C + G

 

G does not exist in DATA, thus it will create blank for D. But is there a way to set non existing column (G) default values to 0 and then D will be equal to A + C ?

 

Thank you,

Gluttony


D = A + C + 0;

or

 

D = A + C;
--
Paige Miller
novinosrin
Tourmaline | Level 20

 

retain g 0;

d=sum(a,c,g);

 

Reeza
Super User

The SUM() statement will ignore missing values.

The SUM operator (+) will not ignore missing values and sets everything to missing when it's blank. 

 

d_operator = a+c+g;
d_statement= sum(a, c, g);

@Gluttony wrote:

Hi everyone,
I need help for this case :

I have a dataset DATA with columns A, B and C

I want to create a new column D = A + C + G

 

G does not exist in DATA, thus it will create blank for D. But is there a way to set non existing column (G) default values to 0 and then D will be equal to A + C ?

 

Thank you,

Gluttony


 

Gluttony
Fluorite | Level 6

Thank you all for your answers !

Gluttony

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1578 views
  • 4 likes
  • 4 in conversation