BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jamuriuk
Fluorite | Level 6

Hello team,

i am trying to group the variable "age" to assign a dummy with groupings 0-14 years, 15-65 years and above 65 years. My variable representing age is z2. How do I set the codes please?

 

James

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you use formats such as @Jim_G suggested then you can avoid adding variables to the data set for almost any analysis tasks. The groups assigned by a format will be used in almost all of the analysis procedures and have the very signficant advantage of if you want to see what the difference may be when you change the boundary for one of the categories you make a new custom format and use that in the procecure code for the age variable. No added variables and if you data is largish then you don't spend extra time with multiple data sets.

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Rhodochrosite | Level 12

x1 = 0 le z2 le 14;

x2 = 15 le z2 le 65;

x3 = z2 gt 65;

jamuriuk
Fluorite | Level 6
Thank you although I did not want to add extra variables x1, x2 and x3. I have apparently used

if age <= 15 then z2=1;else if 12 <= age < 65 then z2=2;else if age >=65 then z2=3; and it has worked.

Thanks so much.

James
Jim_G
Pyrite | Level 9

proc format; value age

0-14='0-14 '
15-65='15-65'
65-120='gt 65';


data; input name $ age ;

format age age.;

cards;
mary 12
joe 60
;

proc print; run

proc format; value age

0-14='0-14 '
15-65='15-65'
65-120='gt 65';


data; input name $ age ;

format age age.;

cards;
mary 12
joe 60
;

proc print; run

 


proc format; value age

0-14='0-14 '
15-65='15-65'
65-120='gt 65';


data; input name $ age ;

format age age.;

cards;
mary 12
joe 60
;

proc print; run

You can use proc format   like this;

 


 proc format; value  age
 
 0-14='0-14  '
 15-65='15-65'
  65-120='gt 65';
  
  data;   input name $ age ;
    format age age.;
   cards;
  mary 12
  joe  60
  ;
 
  proc print;  run 

 

 

 

Jim

ballardw
Super User

If you use formats such as @Jim_G suggested then you can avoid adding variables to the data set for almost any analysis tasks. The groups assigned by a format will be used in almost all of the analysis procedures and have the very signficant advantage of if you want to see what the difference may be when you change the boundary for one of the categories you make a new custom format and use that in the procecure code for the age variable. No added variables and if you data is largish then you don't spend extra time with multiple data sets.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 18752 views
  • 3 likes
  • 4 in conversation