Hi Community;
I need a solution to select the condition on the first character variable then updates the value of the other character variables before creating the final character variable. For example.
Thank you and I am able to find what is wrong in my previous code. Thank you so much.
DATA have;
input a $ b $ c $;
datalines;
0 2 7
1 5 2
1 7 3
0 3 1
;
run;
data want;
set have;
if a="1" then
DO;
select(b);
when ("1") b="0.07";
when ("2") b="0.14";
when ("3") b="0.36";
when ("4") b="0.64";
when ("5") b="1";
when ("6") b="3";
when ("7") b="5";
otherwise;
end;
select(c);
when ("1") c="0.07";
when ("2") c="0.14";
when ("3") c="0.36";
when ("4") c="0.64";
when ("5") c="1";
when ("6") c="3";
when ("7") c="5";
otherwise;
end;
e=b+c;
d=put(e,4.2);
drop e;
END;
run;
This doesn't look particularly difficult. Can you post the code you've attempted, and describe what didn't work?
Read the doc on IF/THEN/ELSE and SELECT/WHEN/OTHERWISE.
Thank you and I am able to find what is wrong in my previous code. Thank you so much.
DATA have;
input a $ b $ c $;
datalines;
0 2 7
1 5 2
1 7 3
0 3 1
;
run;
data want;
set have;
if a="1" then
DO;
select(b);
when ("1") b="0.07";
when ("2") b="0.14";
when ("3") b="0.36";
when ("4") b="0.64";
when ("5") b="1";
when ("6") b="3";
when ("7") b="5";
otherwise;
end;
select(c);
when ("1") c="0.07";
when ("2") c="0.14";
when ("3") c="0.36";
when ("4") c="0.64";
when ("5") c="1";
when ("6") c="3";
when ("7") c="5";
otherwise;
end;
e=b+c;
d=put(e,4.2);
drop e;
END;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.