Hello,
I want to create a column (column_3) based on two other columns (column_1 and column_2).
I know my code is wrong, but something like this
data want;
set have;
column_3=.;
if column_1 eq '.' and column_2>0 then column_3=column_2;
if column_2 eq '.' and column_1 >0 then column_3=column_1;
else if column_1>0 and column_2>0 then column_3 = (column_1+column_2)/2;
run;
Thanks
Assuming that the variables are numeric, you just compare with . not enclosed in quotes. But in your task, you don't have to use if at all. The function mean takes care of missing values:
data havewant;
input col1 col2;
col3 = mean(col1, col2);
datalines;
5 .
. 7
4 6
;
Assuming that the variables are numeric, you just compare with . not enclosed in quotes. But in your task, you don't have to use if at all. The function mean takes care of missing values:
data havewant;
input col1 col2;
col3 = mean(col1, col2);
datalines;
5 .
. 7
4 6
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.