DATA Step, Macro, Functions and more

How to add missing values

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

How to add missing values

Dear Experts,

 

I have a large dataset with so many records, I want to fill the missing values. I to create new two variables, "Principal" and "Vice".

 

data school;

length schoolname $20 teachername $50;

input schoolname 1-21 subject$ 23 ID 26-27 teachername 32-54 Qtype;

cards;

holmes middle school M -1 Doris Wilson 5

holmes middle school M 0 Amy Smith 7

holmes middle school R 1 Mrs. A. T. Whitecotton 6

holmes middle school M 2 Geraldine Carpenter 6

holmes middle school R 3 Jennie Crigler 6

holmes middle school M 4 Lida Gray Gibbs 6

holmes middle school M 5 Irene Ball 6

holmes middle school R 6 Wynona James 6

holmes middle school M 7 Moneaka Elam 8

holmes middle school M 8 Doris Stephens 8

holmes middle school G 9 Catherine Clark 8

holmes middle school M 10 Elma Kemp 8

holmes middle school M 11 Lois Pagett 8

holmes middle school M 12 Ruby Partin 8

holmes middle school H 13 Fances Nugent 8

;

run;

proc sort data=school out=school;

by schoolname ID Qtype;

run;

 

data school1;

set school end=eof;

by schoolname ID Qtype;

if ID=-1 and Qtype=5 then principal=TeacherName;

if ID=0 and Qtype=7 then Vice=TeacherName;

run;

 

the expected output.

 

schoolnameteachernamesubjectIDQtypeprincipalVice
holmes middle schoolDoris WilsonM-15Doris WilsonAmy Smith
holmes middle schoolAmy SmithM07Doris WilsonAmy Smith
holmes middle schoolMrs. A. T. WhitecottonR16Doris WilsonAmy Smith
holmes middle schoolKemp ElmaM18Doris WilsonAmy Smith
holmes middle schoolPagett LoisM18Doris WilsonAmy Smith
holmes middle schoolPartin RubyM18Doris WilsonAmy Smith
holmes middle schoolNugent FancesH18Doris WilsonAmy Smith
holmes middle schoolGeraldine CarpenterM26Doris WilsonAmy Smith
holmes middle schoolCrigler JennieR36Doris WilsonAmy Smith
holmes middle schoolLida Gray GibbsM46Doris WilsonAmy Smith
holmes middle schoolBall IreneM56Doris WilsonAmy Smith
holmes middle schoolJames WynonaR66Doris WilsonAmy Smith
holmes middle schoolElam MoneakaM78Doris WilsonAmy Smith
holmes middle schoolStephens DorisM88Doris WilsonAmy Smith
holmes middle schoolClark CatherineG98Doris WilsonAmy Smith
river middle schoolIone RansdellM-15Ione RansdellAElgelina Atterbury
river middle schoolAElgelina AtterburyM07Ione RansdellAElgelina Atterbury
river middle schoolMWynona JamesR16Ione RansdellAElgelina Atterbury
river middle schoolHopson NannieM18Ione RansdellAElgelina Atterbury
river middle schoolLutie CaldwellM18Ione RansdellAElgelina Atterbury
river middle schoolMaydee MalloryM18Ione RansdellAElgelina Atterbury
river middle schoolLois PagettH18Ione RansdellAElgelina Atterbury
river middle schoolAbigail MarlowM26Ione RansdellAElgelina Atterbury
river middle schoolJennie CriglerR36Ione RansdellAElgelina Atterbury
river middle schoolLida Gray GibbsM46Ione RansdellAElgelina Atterbury
river middle schoolBall IreneM56Ione RansdellAElgelina Atterbury
river middle schoolJames WynonaR66Ione RansdellAElgelina Atterbury
river middle schoolElam MoneakaM78Ione RansdellAElgelina Atterbury
river middle schoolCarpenter ImogeneM88Ione RansdellAElgelina Atterbury
river middle schoolFlowers MarthaG98Ione RansdellAElgelina Atterbury

Accepted Solutions
Solution
a month ago
Super User
Posts: 19,878

Re: How to add missing values

RETAIN PRINCIPAL VICE;

View solution in original post


All Replies
Solution
a month ago
Super User
Posts: 19,878

Re: How to add missing values

RETAIN PRINCIPAL VICE;
Contributor
Posts: 58

Re: How to add missing values

Reeza,

 

Thanks.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 67 views
  • 0 likes
  • 2 in conversation