Hi
I'm using SAS studio (University Edition) on Mac
1) I have several variables that need to be summed together and that resulting sum displayed in summary statistics (and subsequently used for other stats).
E.x. I want to added the following 3 values together to equal "Bobby_hand_cm"
Bobby_palm _cm
Bobby_finger_cm
Bobby_nail_cm
2) How do I combine two values and use the resulting value based on a condition and resulting in a new variable?
Ex: I want to create a code where the person's smoking status (0=never smoked, 1=past smoker, 2=current smoker) is connected to the number of packs smoked per year and equal a new variable ("smoking3")
Something like:
if smoking status=0 then smoking3=1;
if smoking status=1 and packs per year<20 then smokingg3=2;
if smoking status=1 and packs per year >20 then smoking3=3;
etc, etc,
Thanks in advanced for the suggestions! ~J
1)
Bobby_hand_cm=sum(Bobby_palm _cm, Bobby_finger_cm, Bobby_nail_cm);
2)
if smoking_status=0 then smoking3=1;
else if smoking status=1 and packs_per_year le 20 then smokingg3=2;
else if smoking status=1 and packs_per_year gt then smoking3=3;
else;
Show us your data if you want exact code.
Thanks for your help, below
_smkrstat = smoking status
_packyrs = packs per year
(there are no current smokers "2" in this subset). I want the conditional label to be "smkr3"
I guess I didn't need to include the SubID, in there just for my knowledge. Thx~J
_subID | _smkrstat | _packyrs |
1 | 1 | 20 |
2 | 1 | 12 |
3 | 1 | 10 |
4 | 1 | 1 |
5 | 0 | 0 |
6 | 1 | 52 |
7 | 1 | 33 |
8 | 0 | 0 |
9 | 0 | 0 |
10 | 1 | 20 |
11 | 1 | 2 |
12 | 0 | 0 |
13 | 1 | 45 |
14 | 0 | 0 |
15 | 0 | 0 |
16 | 1 | 12 |
17 | 1 | 1 |
18 | 1 | 12 |
19 | 0 | 0 |
20 | 1 | 6 |
21 | 0 | 0 |
22 | 0 | 0 |
23 | 0 | 0 |
24 | 1 | 4 |
25 | 1 | 28 |
26 | 1 | 1 |
27 | 1 | 12 |
28 | 0 | 0 |
29 | 1 | 12 |
30 | 0 | 0 |
31 | 1 | 4 |
32 | 1 | 6 |
33 | 1 | 4 |
34 | 0 | 0 |
35 | 1 | 45 |
36 | 1 | 28 |
37 | 1 | 6 |
38 | 0 | 0 |
39 | 0 | 0 |
40 | 0 | 0 |
I see a number of 2s in that result. The code I used was:
data want;
set have;
if _smkrstat=0 then smkr3=1;
else if _packyrs lt 20 then smkr3=2;
else if _packyrs ge 20 then smkr3=3;
run;
Art, CEO, AnalystFinder.com
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.