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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 982 views
  • 2 likes
  • 3 in conversation