BookmarkSubscribeRSS Feed
NoorulIyn
Calcite | Level 5

I wanted to assign the   formatted age group value created using proc format , as  a variable  for the corresponding ages.How can i get that?Pls help

Age Group

n

   100

   200

300

<65 Years

    25 (25%)

    50 (25%)

   75 (25%)

>= 65 Years

    75 (75%)

   150 (75%)

225 (75%)

>=75 Years

    25 (25%)

    50 (25%)

   75 (25%)

3 REPLIES 3
Reeza
Super User

Use the PUT Function - but note that you'll lost your ability to sort properly unless you keep both variables in your data set.

AGE_GROUP = PUT(age, age_group_format.);

SASKiwi
PROC Star

Assuming your SAS format is called Age_Group, use the PUT function to assign the age group format values to a variable: Age_Group_Var = put(age, Age_Group.);

ballardw
Super User

You didn't provide any raw data, so I create a dummy data set that has an age variable (random ages) and a group variable with values of 100, 200 and 300.

data have;
   do group= 100, 200, 300;
      do i= 1 to group;
         age = round( 100*ranuni(345),1);
         output;
      end;
   end;
run;

/* a custom format. Your example says that you want a multilabel since values >75 are also >65. Only a few procedures will actually honor multiple label type variables

*/

proc format library=work;
value myage  (multilabel)
low - < 65 = '< 65 years'
65 - high  = '>= 65 years'
75 - high  = '>= 75 years'
;
run;

/* This is one of the procedures that will use the multilabel format indicated by MLF on the class statement

this come close to demonstrating the output you showed. We can modify the format to round the row percentage display. If you really need () then there is a bit more work but that is for a separate thread after getting the basics*/

proc tabulate data=have;
   class age / mlf;
   format age myage.;
   class group;
   tables age, group=''*(n='' rowpctn='');
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 933 views
  • 2 likes
  • 4 in conversation