BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AKHILA
Obsidian | Level 7

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;

View solution in original post

2 REPLIES 2
Reeza
Super User
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 

 

 


 

AKHILA
Obsidian | Level 7

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: 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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 865 views
  • 2 likes
  • 3 in conversation