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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 685 views
  • 0 likes
  • 2 in conversation