BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
proc format;
value agegroup_fmt
low - 10 = '<11'
11, 12 = '11-12'
13-14 = '13-14'
15-16 = '15-16'
17-high = '>16'
;
run;

proc tabulate data=sashelp.class out=want ;
class age / preloadfmt  exclusive;
format age agegroup_fmt.;
table age / printmiss misstext='0';
run;

View solution in original post

9 REPLIES 9
Reeza
Super User

What is your question? 

What have you tried so far?

 


@rvsidhu035 wrote:

COUBT.jpeg


 

Reeza
Super User

Here's an example with BMI instead;

 

https://gist.github.com/statgeek/227565537f3dffcd8627f1fe2eff844f

 

Pretty much the same idea.

 

Or I believe there's an example here as well, same BMI, but a step by step walk through

http://video.sas.com/detail/videos/sas-analytics-u/video/4573016759001/performing-conditional-logic-...

rvsidhu035
Quartz | Level 8

from sashelp.class data set develop above table

Reeza
Super User

What have you tried so far? I don't really feel like doing your homework but I'm happy to help while you're doing it. 

 

rvsidhu035
Quartz | Level 8
proc sql;
create table wantk as select 
case when age<11 then '<11' else
	case when age in (11,12) then '11-12' else
		case when age in (13,14) then '13-14' else
			case when age in (15,16) then '15-16' else
				case when age>16 then '>16' else ' ' end
			 end end end end as agegrp,
	count(CALCULATED ageGRP) as count
	from sashelp.class group by ageGRP;quit;
data dummy;
input agegrp $ @@;
cards;
<11 11-12 13-14 15-16 >16
;
run;

proc sql;
create table want3 as select dummy.*,wantk.count from dummy as x  left join wantk as y on 
x.agegrp eq y.agegrp;quit;
proc sql;
create table anser as select 
case when count eq . then 0 else count end as count,agegrp
from want3 order by agegrp desc;
Reeza
Super User

Besides the order that looks correct. Is there something else you're looking for?

 

The answer to your third question is the PRELOADFMT in PROC TABULATE with the MISSING option specified. That would actually do all three at once. 

 

Your current code is SQL, so this would be a very different approach but would take advantage of the automatic SAS processing. 

 

 

 

 

Reeza
Super User
proc format;
value agegroup_fmt
low - 10 = '<11'
11, 12 = '11-12'
13-14 = '13-14'
15-16 = '15-16'
17-high = '>16'
;
run;

proc tabulate data=sashelp.class out=want ;
class age / preloadfmt  exclusive;
format age agegroup_fmt.;
table age / printmiss misstext='0';
run;
ChrisNZ
Tourmaline | Level 20

You are been entered in the contest for the least useful thread title of the year. 🙂

Congratulations!

 

ChrisHemedinger
Community Manager

I fixed the title -- though the question looks like a homework assignment...

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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
  • 9 replies
  • 958 views
  • 2 likes
  • 4 in conversation