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

Hi Folks:

I'd like to impute data where id1name='D'. I'd like to bring current n=21 to a total of  n =120 keeping the frequency distribution of n by idname. I tried it manually by using proc freq on the 'n' and multipling 120 by the resulting percent from proc freq and allocated those numbers to idname. I will have to do the same thing for the rest of id1name such as 'C' too.

 

Could you please help accomplish this imputation task more efficiently than manual?   

 

data have;
input n id1name $ idname $; 
cards;
0 D Buk 
4 D Dalseo 
1 D Dalseong 
1 D Dong 
3 D Jung 
8 D Nam 
2 D Seo 
2 D Suseong
5 C Hart
6 C Sous
; 
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data have;
input n id1name $ idname $; 
cards;
0 D Buk 
4 D Dalseo 
1 D Dalseong 
1 D Dong 
3 D Jung 
8 D Nam 
2 D Seo 
2 D Suseong
5 C Hart
6 C Sous
; 



data new_values;
input id1name $ newBase;
cards;
D 120
C 50
;;;
run;

proc sort data=have;
by id1name;
run;

proc sort data=new_values;
by id1name;
run;

proc freq data=have noprint;
by id1name;
table idname / out=percents;
weight n;
run;

data want;
merge percents new_values;
by id1name;
newValue = round(newBase*percent/100, 1);
run;

View solution in original post

1 REPLY 1
Reeza
Super User
data have;
input n id1name $ idname $; 
cards;
0 D Buk 
4 D Dalseo 
1 D Dalseong 
1 D Dong 
3 D Jung 
8 D Nam 
2 D Seo 
2 D Suseong
5 C Hart
6 C Sous
; 



data new_values;
input id1name $ newBase;
cards;
D 120
C 50
;;;
run;

proc sort data=have;
by id1name;
run;

proc sort data=new_values;
by id1name;
run;

proc freq data=have noprint;
by id1name;
table idname / out=percents;
weight n;
run;

data want;
merge percents new_values;
by id1name;
newValue = round(newBase*percent/100, 1);
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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 367 views
  • 1 like
  • 2 in conversation