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

Hi Community,

 

I need your help with the below problem.

 

If the per ID rows count is <6 then I would like to add the additional missing rows with the Score = 0;

 

data Dsn;
input ID score;
cards;
1 48
1 45
1 50
1 42
1 41
2 51
2 52
2 43
2 52
;
run;

 

Expected Output:

 

IDScore
148
145
150
142
141
10
251
252
243
252
20
20

 

Any help is appreciated. 

 

Thank you for your time. 

 

Best,

SC. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data Dsn;
input ID score;
cards;
1 48
1 45
1 50
1 42
1 41
2 51
2 52
2 43
2 52
;
run;

data want;
 do _n_=1 by 1 until(last.id);
  set dsn;
  by id;
  output;
 end;
 do _n_=_n_+1 to 6;
 score=0;
 output;
 end;
run;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
data Dsn;
input ID score;
cards;
1 48
1 45
1 50
1 42
1 41
2 51
2 52
2 43
2 52
;
run;

data want;
 do _n_=1 by 1 until(last.id);
  set dsn;
  by id;
  output;
 end;
 do _n_=_n_+1 to 6;
 score=0;
 output;
 end;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 447 views
  • 0 likes
  • 2 in conversation