BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ramin1
Obsidian | Level 7
Actually, I want to create a new column name h_67 which will be equal one if the column/variable avg_percent_moneyness >=.67 twice within the sample period otherwise it will be zero. Here, in the code count function is not working as is it not correct. I need help in this regard, hope I will get the reply from you.
I tried the following code but it does not work. Variable holder in the data, is equal 1 if avg_percent_moneyness>= .67 or remains o
Data want;
set have;
If (count(avg_percent_moneyness>=.67))>=2 then holder_67=1;
else 0;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Assuming that by sampling period you mean by gvkey (?), you could use two do until() loops:

 

data want;
count = 0;
do until (last.gvkey);
    set sasforum.t; by gvkey;
    if avg_percent_moneyness >= 0.67 then count + 1;
    end;
h_67 = count >= 2;
do until (last.gvkey);
    set sasforum.t; by gvkey;
    output;
    end;
drop count;
run;
PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

Assuming that by sampling period you mean by gvkey (?), you could use two do until() loops:

 

data want;
count = 0;
do until (last.gvkey);
    set sasforum.t; by gvkey;
    if avg_percent_moneyness >= 0.67 then count + 1;
    end;
h_67 = count >= 2;
do until (last.gvkey);
    set sasforum.t; by gvkey;
    output;
    end;
drop count;
run;
PG
Ramin1
Obsidian | Level 7
Thanks a lot for your quick reply, PGStats. Sampling period means, I have 20 years of data and if the executive scored more than .67 in avg_percent_moneyness twice within that sample year then h_67 will be 1 for that person else 0. I forget to give you one more column in the data that is the ID for each executive and I use by executive id in the do until loop.
In the second do until loop, is it outout or it should be output? When I code outout SAS corrected it as output.
PGStats
Opal | Level 21

I edited my post. I meant output, of course.

PG