data test;
input id days;
datalines;
1 30;
2 90
3 115
;
run;
data test2;
set test1;
if days >=0 and days <=30 then do; range = '0-30'; else
if days >=31 and days <=60 then range ='31-60'; else
if days >=61 and days <=90 then range = '61-90';else
if days >=91 and days <=120 then range = '91-120;
cnt = 1;
run;
In this example nothing would show for the 31-60 category however in that case I want to to show 31-60 with a cnt =0 to reflect this so I can use it in a proc tabulate later on in the program.
use proc formats rather than if then. If then is rather tedious and boring in this case. Well, i wouldn't do it
Deal with that within PROC TABULATE using PRELOADFMT.
If you search those two terms you'll find plenty of examples on how to use it. It will also save you the recoding step, since you can apply the format in PROC TABULATE directly, though you could still recode if you wanted to.
You test data soesn't give enough informatio what you want to count.
Check and addapt next code to your needs:
proc format lib=work;
value range
low - 30 = '0-30'
30 - 60 = '31-60'
60 - 90 = '61-90'
90 - 120= '91-120'
other = '***'
;
run;
data skilton;
retain cnt 1;
length range $6;
range = '0-30'; output;
range = '31-60'; output;
range = '61-90'; output;
range = '91-120'; output;
run;
data test;
input id days;
datalines;
1 30
2 90
3 115
;
run;
data test2;
set test;
length range $6;
range = put(days,range.);
run;
proc sort data=test2; by range; run;
data to_report;
merge skilton test2;
by range;
if id=. then cnt=0;
drop days;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.