BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello. I am trying to group traffic crash injury severity into a new variable.

Basically, my current severity variable is coded as:
'0'= no injury
'1'=minor injury
'2'=moderat injury
'3'=major injury
'4'=major injury unconcious
'5'=fatal injury

Now, I want to determine a way to group these as follows:

New Variable, coded either 'A','B','C','D','None', where:

A= anything from original code that was found in '1','2','3','4','5'
B='2','3','4','5'
C='3','4','5'
D='5'
None='0'

Is there a way to recode the original variable, say it's called INJ (coded '0','1','2','3','4','5'), to the new variable, say INJGRP(coded 'A','B','C','D','None')

Thanks to anyone that can provide me with some help
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
A DATA step SELECT/WHEN/OTHERWISE/END construct would be suitable. Also, for less DATA step coding, consider using a SAS PROC FORMAT and a PUT function in a DATA step to map your data values to a higher-level grouping.

You will find DOC and technical paper references at the SAS support website http://support.sas.com/ or with the Google advanced search argument below:

proc format put function site:sas.com

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
thanks for the help. Would this coding allow me to re-analyze the new variable, for ex/

in INJGRP=A then, else INJGRP=B etc...
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Have a look at the DOC. Here are two examples:

select(injgrp);
when('A','B','C') some_other_var = '1';
when('D','E') some_other_var = '2';
otherwise do;
putlog '>diag99> No match found for ' injgrp=;
end;
end;

select;
when( injgrp in ('A','B','C') ) some_other_var = '1';
when( injgrp in ('D','E') ) some_other_var = '2';
* with no otherwise, SAS will generate error on no-match. ;
end;


Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 894 views
  • 0 likes
  • 2 in conversation