I have the following data
| Case_number | Company | party_role |
| 1 | A | Plaintiff |
| 1 | B | |
| 1 | C | Defendant |
| 1 | D | |
| 2 | E | Plaintiff |
| 2 | F | |
| 2 | G | Defendant |
| 2 | H |
I want the output to look like this.
| Case_number | Company | party_role |
| 1 | A | Plaintiff |
| 1 | B | Plaintiff |
| 1 | C | Defendant |
| 1 | D | Defendant |
| 2 | E | Plaintiff |
| 2 | F | Plaintiff |
| 2 | G | Defendant |
| 2 | H | Defendant |
I tried following code but not working
data want;
set have;
retain repeat1;
if first.case_number then do;
if party_role ne '' then repeat1 = party_role; else do;
if party_role eq '' then party_role = repeat1; end; drop repeat1;
end;
run;
data want;
set have;
retain repeat1;
if first.case_number
then do;
if party_role ne ''
then repeat1 = party_role;
else do;
if party_role eq '' then party_role = repeat1;
end;
drop repeat1;
end;
run;
Do you see the logic mistake?
The log will also alert you to the fact that you tried to use a FIRST. variable without a corresponding BY.
BTW, DROP is a declarative statement. Putting it into a conditional branch is at best misleading.
You probably want this:
data want;
set have;
by case_number;
retain repeat1;
if first.case_number then repeat1 = "";
if party_role ne ""
then repeat1 = party_role;
else party_role = repeat1;
drop repeat1;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.