BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PrinceAde
Obsidian | Level 7

Thank you.

 

<65 : 55 57 63 64 64. i.e <65 should appear 5 times in the column

>=65 : 65 66 67 67 68 68 68 69 70 71 71 71 71  72 72 73 74 76 76 77 77 78.      >=65 should appear 22 times

<75 : 55 57 63 64 64 64 65 66 67 67 68 68 69 70 71 71 71 72 72 73 74.     <75 should appear 21 times

>=75 :  75 76 76 77 77 78     >=75 should appear 6 times.

 

 

That is what I expect for each category if that is possible at all.

 

 

PaigeMiller
Diamond | Level 26

Thank you for clearing this up.

 

Yes it is possible.

 

You will need to run PROC FREQ twice, once using a format that assigns people to the categories <65 and >=65, and once using a format that assigns people to the categories <75 and >=75.

 

proc format;
    value one low-<65='<65' 65-high='>=65';
    value two low-<75='<75' 75-high='>=75';
run;
proc freq data=have;
    tables age;
    format age one.;
run;
proc freq data=have;
    tables age;
    format age two.;
run;
--
Paige Miller
ballardw
Super User

@PrinceAde wrote:

Thank you.

 

<65 : 55 57 63 64 64. i.e <65 should appear 5 times in the column

>=65 : 65 66 67 67 68 68 68 69 70 71 71 71 71  72 72 73 74 76 76 77 77 78.      >=65 should appear 22 times

<75 : 55 57 63 64 64 64 65 66 67 67 68 68 69 70 71 71 71 72 72 73 74.     <75 should appear 21 times

>=75 :  75 76 76 77 77 78     >=75 should appear 6 times.

 

 

That is what I expect for each category if that is possible at all.

 

 


This is possible for limited operations with a custom format defined as MULTILABEL. One thing about such formats is that only Procs Tabulate, Report, Means and Summary (currently) honor them.

data example;
   input age;
datalines;
55
57
63
64
64
64
65
66
67
67
68
68
69
70
71
71
71
72
72
73
74
75 
76
76
77
77
78
;


Proc format;
value myagegroups (multilabel)
low -< 65 = '<65'
65  - high = '>=65'
low -< 75 = '<75'
75  - high = '>=75'
;
run;

proc tabulate data=example;
   class age /mlf ;
   format age myagegroups.;
   table age,
         n
   ;
run;

Which results in

     n
age 6 <65 <75 21 >=65 21 >=75 6

If actual order of output is critical I leave as an exercise to an interested reader to experiment with the Proc Format options Notsorted, the order of the assignment statements in the format values and the ORDER= options in Proc Tabulate as they interact.

 

Note that the MLF option on the Class statement tells SAS to expect a MULTILABEL defined format and use the feature if actually defined in the format.

 

Again, those 4 procedures are the only ones that will do what you are wanting with a single variable and single pass through the data.

PrinceAde
Obsidian | Level 7

Thank you very much sir. I was able to resolve. I did proc freq for <65 and >=65 and another one for <75 and >=75.

 

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
  • 18 replies
  • 6352 views
  • 5 likes
  • 5 in conversation