- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As you can see below, I am re-writing a format into a bunch of conditional statements. This is for binning a variable. Who can write a quick macro to convert the format statements below into the conditional ones above? Any suggestions are appreciated.
if 0 <= ost <= 5 then ost_5 = 1;
else if 6 <= ost <= 10 then ost_5 = 2;
else if 11 <= ost <= 15 then ost_5 = 3;
else if 16 <= ost <= 20 then ost_5 = 4;
else if 21 <= ost <= 25 then ost_5 = 5;
26 - 30 = 6
31 - 35 = 7
36 - 40 = 8
41 - 45 = 9
46 - 50 = 10
;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would imagine that the answer depends on how you are doing the binning and what you will do with the data after it is binned.
In this case, the bin width is 5, so you can simply use that to create the new bin values
data want;
set have;
if ost=0 then bin=1;
else bin=floor((ost-1)/5)+1;
run;
So no macros needed here. And unlikely in general you will need a macro. But, please do tell us what the next steps are.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would imagine that the answer depends on how you are doing the binning and what you will do with the data after it is binned.
In this case, the bin width is 5, so you can simply use that to create the new bin values
data want;
set have;
if ost=0 then bin=1;
else bin=floor((ost-1)/5)+1;
run;
So no macros needed here. And unlikely in general you will need a macro. But, please do tell us what the next steps are.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can create formats from a data set using PROC FORMAT and CTNLIN.
https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/068-2007.pdf
Depending on the format, exactly how that data set is created will differ.
Parsing code will likely take more time.
@pink_poodle wrote:
As you can see below, I am re-writing a format into a bunch of conditional statements. This is for binning a variable. Who can write a quick macro to convert the format statements below into the conditional ones above? Any suggestions are appreciated.
if 0 <= ost <= 5 then ost_5 = 1;
else if 6 <= ost <= 10 then ost_5 = 2;
else if 11 <= ost <= 15 then ost_5 = 3;
else if 16 <= ost <= 20 then ost_5 = 4;
else if 21 <= ost <= 25 then ost_5 = 5;
26 - 30 = 6
31 - 35 = 7
36 - 40 = 8
41 - 45 = 9
46 - 50 = 10
;