BookmarkSubscribeRSS Feed
j4copo
Fluorite | Level 6

Hello everybody,

here it is my first ever loggin into the sas community and my first question. I am a really newbie of SAS then thanks in advance for all the help you will be able to give me. My problem is the following:

In my dataset I have a variable measuring some kinf of exposure for each instance,

ID    Exposure

1     0.45

2     0.56

3     1.46

...    ....

100  0.34

Let's say the total exposure is 35.2, I need to add a new column to this dataset  measuring the relative exposure for each instance, that is:

ID    Exposure    Relative_exposure

1     0.45            0.45/35.2

2     0.56            0.56/35.2

3     1.46            1.46/35.2

...    ....              ....

100  0.34            0.34/35.2

I am sure this is pretty simple, but I am facing problems using with the proc sql.  thanks for your help!

Jacopo

1 REPLY 1
ChrisHemedinger
Community Manager

Something like this perhaps?

data have;

length ID $ 3 Exposure 8;

input ID Exposure;

datalines;

1     0.45

2     0.56

3     1.46

100   0.34

run;

proc sql ;

create table want as select

ID,

Exposure,

exposure/sum(exposure) as relative_exposure

from have;

quit;

Hint: next time post the question in one of the specific forums, such as .

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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
  • 1 reply
  • 3482 views
  • 1 like
  • 2 in conversation