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