BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yuwentaiwan
Calcite | Level 5

Good afternoon fellow SAS users and the overall SAS community.

oba   f         se

1    7/30 

2    5/30

3    9/30

4    11/30

5    21/30

 

SE=f*(1-f)/5,

How can use loop to operation all SE?

Thank you!!

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hope this is what you are expecting

 

data have;
input oba f$;
cards;
1 7/30 
2 5/30
3 9/30
4 11/30
5 21/30
;

data want;
set have;
numerator=input(scan(f,1,'/'),best.);
denominator=input(scan(f,2,'/'),best.);
nd=numerator/denominator;
SE=nd*(1-nd)/5;
run;
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Hope this is what you are expecting

 

data have;
input oba f$;
cards;
1 7/30 
2 5/30
3 9/30
4 11/30
5 21/30
;

data want;
set have;
numerator=input(scan(f,1,'/'),best.);
denominator=input(scan(f,2,'/'),best.);
nd=numerator/denominator;
SE=nd*(1-nd)/5;
run;
Thanks,
Jag
ChrisNZ
Tourmaline | Level 20

For the values you have, @Tom 's reply is probably the best way.

For a generic calculation, here is another way:

data HAVE;
input OBA F $20.;
cards;
1 7/30+4/3
2 5/30
3 9/30
4 11/30
5 21/30-23/16+5/8
;

data WANT;
  set HAVE;
  F1=input(resolve('%sysevalf('||F||')'),32.); putlog F1= ;
  SE=F1*(1-F1)/5;
run;

 

F1=1.5666666667
F1=0.1666666667
F1=0.3
F1=0.3666666667
F1=-0.1125

 

 

 

Tom
Super User Tom
Super User

Do you actually have that "F" value as the strings you are showing?  Or do you have two numeric variables?

 

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2256 views
  • 0 likes
  • 4 in conversation