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

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! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



CIG21
Fluorite | Level 6
Awesome, that's exactly what I needed! Thanks so much.
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 566 views
  • 0 likes
  • 3 in conversation