Help using Base SAS procedures

Some simple counting help

Reply
N/A
Posts: 0

Some simple counting help

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Some simple counting help

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.
N/A
Posts: 0

Re: Some simple counting help

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...
Super Contributor
Super Contributor
Posts: 3,174

Re: Some simple counting help

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.
Ask a Question
Discussion stats
  • 3 replies
  • 128 views
  • 0 likes
  • 2 in conversation