BookmarkSubscribeRSS Feed
jenfumi
Obsidian | Level 7

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

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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.

jenfumi
Obsidian | Level 7

@PeterClemmensen

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
1120
2112
3110
411
500
6152
7133
800
900
10120
1112
1200
13145
1400
1500
16112
1711
18112
1900
2016
2100
2200
2300
2414
25128
2611
27112
2800
29112
3000
3114
3216
3314
3400
35145
36128
3716
3800
3900
4000
art297
Opal | Level 21

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

 

jenfumi
Obsidian | Level 7

@art297

 

Great, thanks! I'll try that

 

~J

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!

What is Bayesian Analysis?

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.

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
  • 4 replies
  • 732 views
  • 0 likes
  • 3 in conversation