BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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. 

3 REPLIES 3
novinosrin
Tourmaline | Level 20

use proc formats rather than if then. If then is rather tedious and boring in this case. Well, i wouldn't do it 

Reeza
Super User

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. 

Shmuel
Garnet | Level 18

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;  

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 652 views
  • 1 like
  • 4 in conversation