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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 256 views
  • 1 like
  • 2 in conversation