Hi users,
I've 2 columns in my data.
data a;
input var1 $20 var2 $80;
cards;
cardio xxxxxxxxxxxxxxxxxxxxx
cardio yyyyyyyyyyyyyyybbbbbbb
derma yyyyyyyyyyyyyyyyyyyyy
derma yyyyyyyyyxxxxxxxxzzzzz
derma rrrrrrrrrrrrrryyyyyyyyuuuuuu
derma yyyyyyyyyyyyyyyyyyyyyuuu
neuro jjjjjjjjjjjuuuuuuuuuuuyyyyyyyy
neuro eeeeeeeeeeeeeetttttttttttyyyyy
neuro mmmmmrrrrrrrrrrrrrrrrtttttttttttt
mental_health zzzzzzzzzzzzzzzzzzz
;
run;
I want to categorize cardio to 1 and derma to 2 and subsequently to others. so a new column must appear where for each value of cardio must have 1. how to do this
Hope this will helps:
proc sort data=a;
by var1;
run;
data want;
set a;
by var1;
retain ord;
if first.var1 then ord+1;
run;
data want;
set a;
if var1 = 'cardio' then cardio=1;
else cardio=0;
if var1='derma' then derma=1;
else derma=0;
if var1 = 'cardio' then disease_code = 1;
else if var1 = 'derma' then disease_code=2;
else disease_code = 99;
run;
If you just want to enumerate the diseases then do this:
proc sort data=a;
by var1;
run;
data want;
set a;
retain disease_code 0;
if first.var1 then disease_code+1;
run;
@sahoositaram555 wrote:
Hi users,
I've 2 columns in my data.
data a;
input var1 $20 var2 $80;
cards;
cardio xxxxxxxxxxxxxxxxxxxxx
cardio yyyyyyyyyyyyyyybbbbbbb
derma yyyyyyyyyyyyyyyyyyyyy
derma yyyyyyyyyxxxxxxxxzzzzz
derma rrrrrrrrrrrrrryyyyyyyyuuuuuu
derma yyyyyyyyyyyyyyyyyyyyyuuu
neuro jjjjjjjjjjjuuuuuuuuuuuyyyyyyyy
neuro eeeeeeeeeeeeeetttttttttttyyyyy
neuro mmmmmrrrrrrrrrrrrrrrrtttttttttttt
mental_health zzzzzzzzzzzzzzzzzzz
;
run;
I want to categorize cardio to 1 and derma to 2 and subsequently to others. so a new column must appear where for each value of cardio must have 1. how to do this
Hope this will helps:
proc sort data=a;
by var1;
run;
data want;
set a;
by var1;
retain ord;
if first.var1 then ord+1;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.