SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mayasak
Quartz | Level 8

Hi,

 

I have data with whole numbers values (34, 78...) in all hospitals except for one who has the numbers as (16%, 65% which ended in having .16 and .65 in the final data set...). Is there a way to change those values to whole numbers such as 16 and 65?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Even though you wrote the WHERE statement after the IF statement is will actually apply to the data as it is read. So your resulting dataset will only have the data from the one hospital.

 

If you did not intend to subset the data then instead include the extra test in the IF condition.

data new;
  set test;
  if variable<1 and hospital = 'abc' then variable=variable*100;
run;

 

View solution in original post

4 REPLIES 4
Reeza
Super User
How do you know which ones are not correct?
Assuming all are less than one you could do something like:


if variable<1 then variable=variable*100;

mayasak
Quartz | Level 8
It's only one hospital so I'm wondering if I can apply that for hospital = 'abc' such as
data new;
set test;
if variable<1 then variable=variable*100;
where hospital = 'abc';
run;
Tom
Super User Tom
Super User

Even though you wrote the WHERE statement after the IF statement is will actually apply to the data as it is read. So your resulting dataset will only have the data from the one hospital.

 

If you did not intend to subset the data then instead include the extra test in the IF condition.

data new;
  set test;
  if variable<1 and hospital = 'abc' then variable=variable*100;
run;

 

FreelanceReinh
Jade | Level 19

@mayasak wrote:
if variable<1 then variable=variable*100;

Hi @mayasak,

 

You may be lucky with your data, but in general I would use the ROUND function (or the INT function in your particular case) to ensure that the resulting numbers are exactly what you would expect:

 

... then variable=round(variable*100,1e-9);

Thus you avoid surprises like in this log (obtained with SAS 9.4M5 on Windows):

77   data _null_;
78   if 0.14*100~=14 & 0.29*100<29 & 0.55*100>55 then put 'Surprised?';
79   run;

Surprised?
NOTE: DATA statement used (Total process time):

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1838 views
  • 3 likes
  • 4 in conversation