BookmarkSubscribeRSS Feed
sg_kr
Obsidian | Level 7

Hi, 

i have a datasets with policy numbers with agent and their pc's like below

pol_noagt_noagt_namePC
3011x10
3022y10
3012y5
3031x20
3032y10

 

here there are few policies which are shared by both the agents like pol_no 301 and 303, but the pc's owned by the agents for same polices are different.

 

Now,i am trying to find the combinations based on their policy number and also whoever comes as agt_no1, his sharing(pc's) should assign to the pc column.

 

below is the code which i wrote but:

 


rsubmit;


title 'Find out max Joint Agent per Policy';


data polds2;
set polds;
by group PPGFirm pol_no;
retain &ValueVarList2.;
if first.pol_no then count=0;
count+1;
run;

*indicate #agents joint-sale*;
proc freq;tables count/list missing out=MaxAgtCount;run;
data _null_;
set MaxAgtCount;
Counter=count+0;
call symput ('MaxAgtCount',counter);
run;
%put &MaxAgtCount.;

title 'Add all the joint agent per each policy';
%macro JointDetail;

 

data polds3(keep=group PPGFirm pol_no Count &ValueVarList2. %do y=1 %to 7; agt_no&y. Agtname&y. %end;);
retain pol_no &ValueVarList2. %do y=1 %to 7; agt_no&y. Agtname&y. %end;;
set polds2;
by group PPGFirm pol_no;

length %do y=1 %to 7; agt_no&y. $7. Agtname&y. $70. %end;;
retain %do y=1 %to 7; agt_no&y. Agtname&y. %end;;

if first.pol_no then do;
%do y=1 %to 7;
agt_no&y.=''; Agtname&y.='';
%end;
end;
%do y=1 %to &MaxAgtCount.;
if Count=&y. then do;
agt_no&y.=agt_no; Agtname&y.=Agtname;
end;
%end;
run;


data polds3_1(keep=group PPGFirm pol_no Count &ValueVarList2. %do y=1 %to 7; agt_no&y. Agtname&y. %end;);
retain pol_no &ValueVarList2. %do y=1 %to 7; agt_no&y. Agtname&y. %end;;
set polds2;
by group PPGFirm pol_no;

length %do y=1 %to 7; agt_no&y. $7. Agtname&y. $70. %end;;
retain %do y=1 %to 7; agt_no&y. Agtname&y. %end;;

if last.pol_no then do;
%do y=1 %to 7;
agt_no&y.=''; Agtname&y.='';
%end;
end;
%do y=1 %to &MaxAgtCount.;
if Count=&y. then do;
agt_no&y.=agt_no; Agtname&y.=Agtname;
end;
%end;
run;

 

 

desired output:

pol_noagt_no1agt_name1agt_no2agt_name2pc
3011x2y10
3012y1x5
3022y  10
3031x2y20
3032y1x10

 

please help me with the small modifications that i can do on the above code.

 

thanks in advance.

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

First of all, it is rarely a good idea to make the data set wide.

 

Secondly, how is pc=5 in the second row of your desired output calculated?

sg_kr
Obsidian | Level 7

bcoz, he owns those pc's for that pol_no

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 601 views
  • 0 likes
  • 2 in conversation