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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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