Pages

Tuesday, June 12, 2012

Creating a new variable by compressing several variables

Creating a new variable by compressing several variables


test family rep female male tree
1 A 1 F43 M28 1
1 B 1 F22 M02 2
1 B 2 F22 M02 4

data a ; set a;
ID=compress(test||family||rep||tree); *Combine factors using ||, remove any trailing blank using COMPRESS;

CROSSno=trim(female||male); *Combine FEMALE and MALE variables with ||, remove any trialing blank using TRIM;
CROSSblank=female||male ; * Trim or Compress is not used. New variable may contain blanks;

Proc print data=a ; run;
Result:

test family rep female male tree ID CROSSno CROSSblank
1 A 1 F43 M28 1 1A11 F43M28 F43 M28 
1 B 1 F22 M02 2 1B12 F22M02 F22 M02
1 B 2 F22 M02 4 1B24 F22M02 F22 M02

No comments:

Post a Comment