BookmarkSubscribeRSS Feed
ma23nu32el
Calcite | Level 5

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

3 REPLIES 3
smantha
Lapis Lazuli | Level 10

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;
ballardw
Super User

@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?

Reeza
Super User
I would recommend separating your steps. First read the data in. Make sure that is working correctly and then do your cleaning in a second step. This allows you to test each stage separately and more easily identify errors.

As BallardW indicated, the variable, dblehdr, is never read in or exists prior to usage so that will not work.


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.;

run;


data trp3;
set trp2;
if Date='' then delete;
if dblehdr= indexc(Date,'()') then
dblehdr=1;
run;


hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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