BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello, all:

 

My oringinal data set has "MSM" in variable "Risk" corespored to "Man" in variable "Race".   Now, I would like to add one more "All" in variable "Race" when there are either "MSM" or "MSM-B" in variable "Risk".  The final format example is shown below.  How to approach this?  Please help.  Thanks.

 

Oringinal format:

Risk  Race

MSM  Man

MSM-B  Man

 

Final format:

Risk  Race

MSM  All

MSM  Man

MSM-B  All

MSM-B  Man

2 REPLIES 2
LinusH
Tourmaline | Level 20

Just a conditional assignment and an explicit output in a data step-

Data never sleeps
ybz12003
Rhodochrosite | Level 12

I wrote the code below

 

Data A;

set B;

if RISK in ('MSM', 'MSM-B') then RACE='Man';

run;

 

I got the result for replacing the "All" with "Man".  However, I couldn't get extra line for "All".  How to get "All" and "Man" together to corresponded to "MSM" and "MSM-B"?

 

Oringinal format:

Risk  Race

MSM  All

MSM-B  All

 

My SAS format:

Risk  Race

MSM  Man

MSM-B  Man

 

The final format I would like to modify is:

Risk  Race

MSM  All

MSM  Man

MSM-B  All

MSM-B  Man

 

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 693 views
  • 0 likes
  • 2 in conversation