BookmarkSubscribeRSS Feed
rileym94
Calcite | Level 5

I had 0 experience with SAS at the beginning of this month, but I've done pretty well on figuring things out over the last 3 weeks, except this... Smiley Frustrated

 

We have a lovely proc report that I wrote, which lists students by level and age. The output is as follows: 

 

Annotation 2019-08-23 111317.png

 

 

 

 

 

 

 

Class Level is "Undergraduate" or "Graduate"

Age Group is <=18, 19-34, >=35

 

%Level Total should be filled in with the percentage of [Level] students who are 15 years old, 16, 17, etc. like so

 

Annotation 2019-08-23 111317.png

 

 

 

 

 

 

 

 

proc sort data=stud;
by rpt_age_sort rpt_age;
run;

title1 c=blue h=2 'Student Age & Gender';
Title2 c=Black "&comp_semester to &semester";
ods proclabel 'Student Age';
proc report data=stud nowindows out=dual split='*';
 column (levl_desc rpt_age_group rpt_age) term_code_key, (gender N percnt) ;

   define levl_desc / right group order=data  'Class Level';
   break after  levl_desc  /summarize skip OL style=[font_weight=bold background=Ligr];
   define rpt_age_group / right group order=data 'Age Group';
   break after  rpt_age_group  /summarize skip OL style=[font_weight=bold background=Ligr];
   define rpt_age / right group order=data 'Age';
   define gender / right group across  format=$gender.      'Gender';
   define term_code_key / format=$cester. center group across order=data  'Semester' STYLE={font_weight=bold foreground=blue};;
   define n / center 'Total Students' style=[background=libgr font_weight=bold];
   define percnt /computed center format=percent8.1 "% Level Total" style=[background=libgr font_weight=bold];
   rbreak after   /summarize skip DOL  style=[background=Ligr font_weight=bold] ;

compute percnt;
   percnt=levl_desc/count;
endcomp;


run;

I've tried searching everywhere I can to find an example that matches my case, but none of them are exactly fitting. I know now that my compute is a little wonky because i'm trying to use levl_desc as part of the calculation, but it's a text value... I'm brand new, don't judge! Smiley LOL

 

Any help or advice would be greatly appreciated. I'm about as new as you can be when it comes to working with SAS, and most of the work I'll do in SAS is center around grouping stuff in proc report and generating percentages, so any advice would be GREATLY appreciated. 

1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi:
Well, one problem I see is that where does "COUNT" in the formula for percent come from? I do not see COUNT on the COLUMN statement. PROC REPORT can ONLY use variables that are on hte COLUMN statement. My guess is you want to use the N statistic, which is the count, but needs to be referenced by the statistic name in your formula.

But another issue is that Levl_desc looks like a character variable, so that's not going to work in your formula, so even if you get the denominator correct, you also need to get the numerator correct. My guess is that you want the numerator to be the count and the denominator to be the total of all undergraduates (8764 in the above screen shot).

These 2 papers may help you:
http://support.sas.com/resources/papers/proceedings14/SAS388-2014.pdf ( to see how to do calculations with items under and ACROSS variable..and you have 2 ACROSS variables, so you'll need to be very careful).
https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf for COMPUTE block examples.

Hope this helps,
Cynthia

Cynthia

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1038 views
  • 0 likes
  • 2 in conversation