I have to create a 0-1 variable called dblehdr
that indicates whether the triple play occurred during a game that was part of a double-header this is what I have but is not returning the value that I need, what I'm doing wrong?
data trp2;
infile trpd2 DLM=',' DSD Firstobs=2 missover;
input Year Date :$12. Game IAT Team :$12. LG $ HA $ oppteam :$12.
OLG $ players :$150. inn $ SCRVH $ batter :$20. runner1 :$20. runner2 :$20.
runner3 :$20.;
if Date='' then delete;
if dblehdr= indexc(Date,'()') then do;
dblehdr=1;
end;
Thank you
sample input data would be good. How is date coded for double header? does it have two values in parantheses. dblehdr is not previously defined so it will never be true. try the code below instead.
data trp2;
infile trpd2 DLM=',' DSD Firstobs=2 missover;
input Year Date :$12. Game IAT Team :$12. LG $ HA $ oppteam :$12.
OLG $ players :$150. inn $ SCRVH $ batter :$20. runner1 :$20. runner2 :$20.
runner3 :$20.;
if Date='' then delete;
dblehdr= (indexc(Date,'()')>0) ;
run;
@ma23nu32el wrote:
I have to create a 0-1 variable called
dblehdr
that indicates whether the triple play occurred during a game that was part of a double-header this is what I have but is not returning the value that I need, what I'm doing wrong?
data trp2;
infile trpd2 DLM=',' DSD Firstobs=2 missover;
input Year Date :$12. Game IAT Team :$12. LG $ HA $ oppteam :$12.
OLG $ players :$150. inn $ SCRVH $ batter :$20. runner1 :$20. runner2 :$20.
runner3 :$20.;
if Date='' then delete;
if dblehdr= indexc(Date,'()') then do;
dblehdr=1;
end;
Thank you
You code does not show where dblehdr is read from. So this statement
if dblehdr= indexc(Date,'()') then do;
has a serious problem because you are using the value of the variable dblehdr in the IF before it has a value assigned. So the if is always false.
SAS will return 0 for "false" and 1 for "true" when using logical comparisons. So @smantha's code will assign a 1 if the "date" has either a ( or ) character in it.
And what value would indicate a triple play? What variable?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.