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?

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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