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


Dear Friends,

I have a data which has a firm identier and a dummy variable SOX. Although most of the firms in my sample have both 0 and 1 values for SOX, some firms have only 0 or 1 value for SOX. I want to delete firms that do not have both 0 or 1 for SOX.

Firm       SOX

A             0

A             1

B             0

B             1

C             0

D             0

D             1

E             1

Expected Output

Firm       SOX

A             0

A             1

B             0

B             1

D             0

D             1

I would appreciate if someone would provide me with the code.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data have;

input Firm $      SOX;

cards;

A             0

A             1

B             0

B             1

C             0

D             0

D             1

E             1

;

data want;

  set have;

   by firm;

   if first.firm and last.firm then delete;

   run;

   proc print;run;

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

data have;

input Firm $      SOX;

cards;

A             0

A             1

B             0

B             1

C             0

D             0

D             1

E             1

;

data want;

  set have;

   by firm;

   if first.firm and last.firm then delete;

   run;

   proc print;run;

pk2012
Calcite | Level 5

Thank you Linlin.

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
  • 2 replies
  • 437 views
  • 0 likes
  • 2 in conversation