Hi!
I am having this sample datasets which contains values and their units (K stands for ten thousands, M for millions). My goal is to have a new table (want) that adds the zeros, depending on K or M, to the value column variables and shows the value as proper number. I tried it with the below code but it did not work (did not get an error either but it didn't change anything).
In the end, the table want should ideally look like this (tips on how to remove the redudandant unit columns are also appreciated):
"value
10000
15000
19000000
4000000"
data example; input value unit$; datalines; 10 K 15 K 19 M 4 M ; run; data want; set example; if unit ="K" then value=value+000; else value=value+000000; run;
Any ideas on how I could achieve that? Thanks already in advance! 🙂
As far as I know "adding zeros" means multiplying by...
data want(drop=unit);
set example;
if unit ="K" then value=value*1000;
else value=value*1000000;
run;
Bart
As far as I know "adding zeros" means multiplying by...
data want(drop=unit);
set example;
if unit ="K" then value=value*1000;
else value=value*1000000;
run;
Bart
With numeric data, 000 is equal to 0, so your addition statements do in effect nothing. You need to multiply.
If k stands fo decimal "kilo", multiply by 1000, but if it stands for IT K (note the capital letter), multiply by 1024. Similarly, m should be multiplied by 1000000, but M by 1024*1024.
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.