turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Restricting dataset to variables with whole intege...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-23-2018 09:03 AM

I have a dataset with a numeric variable that has the numeric value of several different lab tests. Some of these are whole integers (25 or 100 etc) but some are with decimals (25.6849 or 100.329 etc). I need to restrict this dataset to the observations where this variable is represented by whole numbers only. I don’t want it to round the decimals to whole numbers, I want to delete any observation that has a decimal value. I have tried converting it to a text variable with PUT not specifying decimal places but SAS rounds the values out to whole numbers in the outputted text variable. Then I specified decimal places in the PUT function so I can pick out the decimal with substring function but for some reason, SAS still rounds up the number and adds 0 after the decimal so that 239.199965 becomes 239.200000 which doesn’t help me.

Any suggestions?

Many thanks all

Accepted Solutions

Solution

03-23-2018
09:15 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mmaskew

03-23-2018 09:10 AM

Use a where condition:

```
data have;
input x1;
cards;
1
2
1.5
;
run;
data want;
set have;
where int(x1) = x1;
run;
proc print data=want noobs;
run;
```

Result:

x1 1 2

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

All Replies

Solution

03-23-2018
09:15 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to mmaskew

03-23-2018 09:10 AM

Use a where condition:

```
data have;
input x1;
cards;
1
2
1.5
;
run;
data want;
set have;
where int(x1) = x1;
run;
proc print data=want noobs;
run;
```

Result:

x1 1 2

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to KurtBremser

03-23-2018 09:15 AM

Awesome! Thanks so much for the quick response! That worked great..