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

Please have a look into below 

 

data a;
infile cards;
input cardtype ar ncust ;
cards;
271 350 10001
271 680 10002
371 720 10003
371 980 10004
203 1002 10001
203 401 10005
304 3050 10003
;
run;

data b;
infile cards;
input ncust age sex $;
cards;
10001 28 M
10002 29 F
10003 30 M
10004 31 F
10005 32 F
run;

How do we write the code for to get the following output result using the above sas datasets a and b

Result:

 

„ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†

|        |                         Sex                         |

|        |--------------------------|--------------------------|

|        |          Female          |           Male           |

|        |--------|--------|--------|--------|--------|--------|

|        | No.of  |        |        | No.of  |        |        |

|        |  A/Cs  |   AR   |   %    |  A/Cs  |   AR   |   %    |

|--------|--------|--------|--------|--------|--------|--------|

|ncust   |        |        |        |        |        |        |

|--------|        |        |        |        |        |        |

|10001   |       .|       .|       .|       2|   1,352|    26.4|

|--------|--------|--------|--------|--------|--------|--------|

|10002   |       1|     680|    33.0|       .|       .|       .|

|--------|--------|--------|--------|--------|--------|--------|

|10003   |       .|       .|       .|       2|   3,770|    73.6|

|--------|--------|--------|--------|--------|--------|--------|

|10004   |       1|     980|    47.5|       .|       .|       .|

|--------|--------|--------|--------|--------|--------|--------|

|10005   |       1|     401|    19.5|       .|       .|       .|

|--------|--------|--------|--------|--------|--------|--------|

|Total   |       3|   2,061|   100.0|       4|   5,122|   100.0|

|--------|--------|--------|--------|--------|--------|--------|

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@chandu1 wrote:

Please have a look into below 



How do we write the code for to get the following output result using the above sas datasets a and b

Result:

 

„ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†

|        |                         Sex                         |

|        |--------------------------|--------------------------|

|        |          Female          |           Male           |

|        |--------|--------|--------|--------|--------|--------|

|        | No.of  |        |        | No.of  |        |        |

|        |  A/Cs  |   AR   |   %    |  A/Cs  |   AR   |   %    |

|--------|--------|--------|--------|--------|--------|--------|

|ncust   |        |        |        |        |        |        |

|--------|        |        |        |        |        |        |

|10001   |       .|       .|       .|       2|   1,352|    26.4|

What is an "A/C"?  How do we tell from your data? What  statistic is requested for AR? % of what?

Guessing for answers to above:

data a;
infile cards;
input cardtype ar ncust ;
cards;
271 350 10001
271 680 10002
371 720 10003
371 980 10004
203 1002 10001
203 401 10005
304 3050 10003
;
run;

data b;
infile cards;
input ncust age sex $;
cards;
10001 28 M
10002 29 F
10003 30 M
10004 31 F
10005 32 F
run;
proc sort data=a;
  by ncust;
run;
proc sort data=b;
  by ncust;
run;

data want;
  merge a b;
  by ncust;
run;

proc tabulate data=want;
   class ncust sex;
   var ar;
   table ncust all='Total',
         sex * ar=''*(n='# A/C' sum='AR'*f=comma6. colpctsum='%'*f=5.1)
         /misstext=' '
   ;
run;

If you want "Female" instead of "F" you need to create custom format to display the text you want and associate that format with the SEX variable.

 

If you are going to paste text from the OUTPUT window open a code box with the forum's {I} or "running man" icon to keep the message windows from reformatting text.

View solution in original post

3 REPLIES 3
ErikLund_Jensen
Rhodochrosite | Level 12

First a data step to merge a and b, and then a proc tabulate to present the result.
ballardw
Super User

@chandu1 wrote:

Please have a look into below 



How do we write the code for to get the following output result using the above sas datasets a and b

Result:

 

„ƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ†

|        |                         Sex                         |

|        |--------------------------|--------------------------|

|        |          Female          |           Male           |

|        |--------|--------|--------|--------|--------|--------|

|        | No.of  |        |        | No.of  |        |        |

|        |  A/Cs  |   AR   |   %    |  A/Cs  |   AR   |   %    |

|--------|--------|--------|--------|--------|--------|--------|

|ncust   |        |        |        |        |        |        |

|--------|        |        |        |        |        |        |

|10001   |       .|       .|       .|       2|   1,352|    26.4|

What is an "A/C"?  How do we tell from your data? What  statistic is requested for AR? % of what?

Guessing for answers to above:

data a;
infile cards;
input cardtype ar ncust ;
cards;
271 350 10001
271 680 10002
371 720 10003
371 980 10004
203 1002 10001
203 401 10005
304 3050 10003
;
run;

data b;
infile cards;
input ncust age sex $;
cards;
10001 28 M
10002 29 F
10003 30 M
10004 31 F
10005 32 F
run;
proc sort data=a;
  by ncust;
run;
proc sort data=b;
  by ncust;
run;

data want;
  merge a b;
  by ncust;
run;

proc tabulate data=want;
   class ncust sex;
   var ar;
   table ncust all='Total',
         sex * ar=''*(n='# A/C' sum='AR'*f=comma6. colpctsum='%'*f=5.1)
         /misstext=' '
   ;
run;

If you want "Female" instead of "F" you need to create custom format to display the text you want and associate that format with the SEX variable.

 

If you are going to paste text from the OUTPUT window open a code box with the forum's {I} or "running man" icon to keep the message windows from reformatting text.

chandu1
Calcite | Level 5
Thanks for your help

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
  • 3 replies
  • 557 views
  • 0 likes
  • 3 in conversation