Thank you for your PROC FREQ data aggregation solution (Method 1 SAS code below). I have also provided two additional solutions using PROC SUMMARY and PROC SQL (Methods 2 and 3 SAS code below). Below is the SAS Output for aggregated data. DUPERSID RXNDC RXNAME count ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 2320018102 -15 ANTICOAGULANTS 2 2320038101 -15 ANTICOAGULANTS 3 2320105101 -15 INSULIN 4 2320222101 73070010011 INSULIN ASPA 8 Question: What DATA step code would I write to create the output data set (e.g., example observation below) based on the above data set as input? Any hints (or references) would be appreciated. DUPERSID RXNDC RXNAME count RXNDC1 RXNAME2 RXNDC1 RXNAME2 ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ 2320018102 -15 ANTICOAGULANTS 2 -15 ANTICOAGULANTS -15 ANTICOAGULANTS ******************************************************************** data testdata; infile datalines truncover ; input DUPERSID :$10. RXNDC :$char11. RXNAME & $50.; datalines; 2320018102 -15 ANTICOAGULANTS 2320018102 -15 ANTICOAGULANTS 2320038101 -15 ANTICOAGULANTS 2320038101 -15 ANTICOAGULANTS 2320038101 -15 ANTICOAGULANTS 2320105101 -15 INSULIN 2320105101 -15 INSULIN 2320105101 -15 INSULIN 2320105101 -15 INSULIN 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA 2320222101 73070010011 INSULIN ASPA ; proc print data=testdata; run; title 'Method 1'; Proc freq data=work.testdata noprint; tables dupersid * rxndc * rxname / list nopercent out=FreqCount (drop=percent); run; proc print data=work.FreqCount; run; title 'Method 2'; proc summary data=testdata nway ; by dupersid rxndc rxname; output out=want (rename=(_freq_=count)drop=_type_) ; run; proc print data=work.want; run; title 'Method 3'; proc sql; select dupersid, rxndc, rxname, count(*) as count from testdata group by dupersid, rxndc, rxname; quit;
... View more