<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: error Handling: in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29188#M5488</link>
    <description>I can't really follow you. I can't see vwhere WORK.ERRORS is created. Please attach full code and a LOG if the execution does not work the way you expect. To investigate macro logic turn on MLOGIC MPRINT and SYMBOLGEN options.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
    <pubDate>Fri, 08 May 2009 09:47:41 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2009-05-08T09:47:41Z</dc:date>
    <item>
      <title>error Handling:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29187#M5487</link>
      <description>%macro check_errors;&lt;BR /&gt;
/*delete any stray errors data set prior to doing the lookup*/&lt;BR /&gt;
proc datasets library=work; delete errors; quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table check_physician as&lt;BR /&gt;
    select distinct (d1.physician),&lt;BR /&gt;
   case&lt;BR /&gt;
      when d1.physician ne d2.phy_name  then 'YES' else 'NO'&lt;BR /&gt;
  end as is_it_newname&lt;BR /&gt;
      from whole d1 left outer join caremarkphysicians  d2 on d1.physician=d2.Phy_Name&lt;BR /&gt;
      where d1.physician ne '';&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/*Call the DATA step EXIST function with %SYSFUNC to determine if data set exists.*/ &lt;BR /&gt;
%let err = %sysfunc(exist(work.errors)); &lt;BR /&gt;
%if err = 0 %then %do;&lt;BR /&gt;
&lt;BR /&gt;
/*  INSERT CODE HERE TO RUN IF ERRORS DATA SET DOES NOT EXIST */&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
%put Errors occurred. Exporting Errors data set to erordatabase; &lt;BR /&gt;
 proc export data=work.errors&lt;BR /&gt;
   dbms=excel2000&lt;BR /&gt;
   outfile='c:\errors.xls';run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
 &lt;BR /&gt;
%check_errors;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
For the above code errors dataset is created with either "Yes" or "No" or both values.In any case the program will not execute. Can I have the program execute if  is_it_newname ="NO" and if "YES" the go to the end of program.</description>
      <pubDate>Thu, 07 May 2009 20:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29187#M5487</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-05-07T20:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: error Handling:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29188#M5488</link>
      <description>I can't really follow you. I can't see vwhere WORK.ERRORS is created. Please attach full code and a LOG if the execution does not work the way you expect. To investigate macro logic turn on MLOGIC MPRINT and SYMBOLGEN options.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Fri, 08 May 2009 09:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29188#M5488</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-05-08T09:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: error Handling:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29189#M5489</link>
      <description>%macro check_errors;&lt;BR /&gt;
/*delete any stray errors data set prior to doing the lookup*/&lt;BR /&gt;
proc datasets library=work; delete errors; quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table errors as&lt;BR /&gt;
    select distinct (d1.physician),&lt;BR /&gt;
   case&lt;BR /&gt;
      when d1.physician ne d2.phy_name  then 'YES' else 'NO'&lt;BR /&gt;
  end as is_it_newname&lt;BR /&gt;
      from whole d1 left outer join caremarkphysicians  d2 on d1.physician=d2.Phy_Name&lt;BR /&gt;
      where d1.physician ne '';&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*Call the DATA step EXIST function with %SYSFUNC to determine if data set exists.*/ &lt;BR /&gt;
%let err = %sysfunc(exist(work.errors)); &lt;BR /&gt;
%if err = 0 %then %do;&lt;BR /&gt;
&lt;BR /&gt;
/*  INSERT CODE HERE TO RUN IF ERRORS DATA SET DOES NOT EXIST */&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table whole_v1 as&lt;BR /&gt;
	select d1.*,&lt;BR /&gt;
   case&lt;BR /&gt;
       when d2.nEWPHY_NAME eq ''  then d1.physician&lt;BR /&gt;
     else d2.nEWPHY_NAME&lt;BR /&gt;
   end as physician_name&lt;BR /&gt;
    from whole d1 left outer join caremarkphysicians  d2 on d1.physician=d2.Phy_Name;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 create table whole_v2 as&lt;BR /&gt;
  select a.*,b.terr_id,b.bsm,b.region,b.city&lt;BR /&gt;
   from whole_v1(drop=md_city)  a left outer join caremarkziptoterr  b on a.md_zip=b.zip;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*****&lt;BR /&gt;
Report1:Prescriber Report Summary&lt;BR /&gt;
******/&lt;BR /&gt;
options missing='';&lt;BR /&gt;
ods html file="T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\report1- %sysfunc(DATE(),mmddYYd10.).xls";&lt;BR /&gt;
proc report data=whole_v2 nowd NOWINDOWS HEADLINE MISSING;&lt;BR /&gt;
	COLUMN terr_id  bsm physician_name total_scripts, year, productgroup;&lt;BR /&gt;
	define terr_id/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define bsm/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE physician_name / group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE year / across ''&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1};&lt;BR /&gt;
	DEFINE productgroup / across &lt;BR /&gt;
	STYLE (header) = [FOREGROUND = black font_size=1];&lt;BR /&gt;
	DEFINE total_scripts / sum format=comma12. ' '&lt;BR /&gt;
	STYLE (COLUMN) = { font_size=1.5};&lt;BR /&gt;
	/****&lt;BR /&gt;
    reason to create compute blocks:&lt;BR /&gt;
	repeat GROUP or ORDER variables for every row.&lt;BR /&gt;
	***/&lt;BR /&gt;
	compute terr_id;&lt;BR /&gt;
	if terr_id ne '' then hold=terr_id;&lt;BR /&gt;
	if terr_id eq '' then terr_id=hold;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	compute bsm;&lt;BR /&gt;
	if bsm ne '' then hold1=bsm;&lt;BR /&gt;
	if bsm eq '' then bsm=hold1;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	break after terr_id/summarize skip ol style=[font_weight=bold background=grey];&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
  /***************** End of report1*************/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*****&lt;BR /&gt;
Report2:Caremark Prescriber Report&lt;BR /&gt;
******/&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
 create table rpt2a as&lt;BR /&gt;
  select distinct terr_id,region,bsm, md_zip,md_addr1,md_addr2,city,md_state,physician_name, sum(total_scripts) as T_yr, productgroup&lt;BR /&gt;
   from whole_v2&lt;BR /&gt;
   group by terr_id,region, md_zip, bsm, physician_name, productgroup,md_zip,city,md_state;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
	&lt;BR /&gt;
ods html file="T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\rpt2a-%sysfunc(DATE(),mmddYYd10.).xls";&lt;BR /&gt;
proc report data=rpt2a nowd NOWINDOWS HEADLINE MISSING;&lt;BR /&gt;
	COLUMN terr_id region bsm md_zip  physician_name md_addr1 md_addr2 city md_state t_yr, productgroup;&lt;BR /&gt;
	define terr_id/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define region/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define bsm/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_zip/group '5 digit zip'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {htmlstyle="mso-number-format:\@" just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE physician_name / group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
/*	DEFINE year / across*/&lt;BR /&gt;
/*	STYLE (header) = {just=left  font_size=1};*/&lt;BR /&gt;
	DEFINE year_month / across&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1};&lt;BR /&gt;
	DEFINE productgroup / across &lt;BR /&gt;
	STYLE (header) = [FOREGROUND = black font_size=1];&lt;BR /&gt;
	DEFINE t_yr / format=comma9. ''&lt;BR /&gt;
	STYLE (column) = {font_size=1};&lt;BR /&gt;
	DEFINE t_yr_m/ format=comma9. ''&lt;BR /&gt;
	STYLE (column) = {font_size=1};&lt;BR /&gt;
	define md_addr1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_addr2/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define city/group 'md_city'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_state/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
   	/****&lt;BR /&gt;
    reason to create compute blocks:&lt;BR /&gt;
	repeat GROUP or ORDER variables for every row.&lt;BR /&gt;
	***/&lt;BR /&gt;
	compute terr_id;&lt;BR /&gt;
	if terr_id ne '' then hold=terr_id;&lt;BR /&gt;
	if terr_id eq '' then terr_id=hold;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	compute bsm;&lt;BR /&gt;
	if bsm ne '' then hold1=bsm;&lt;BR /&gt;
	if bsm eq '' then bsm=hold1;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	compute region;&lt;BR /&gt;
	if region ne '' then hold3=region;&lt;BR /&gt;
	if region eq '' then region=hold3;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	break after terr_id/summarize skip ol style=[font_weight=bold background=grey];&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
 create table rpt2b as&lt;BR /&gt;
  select distinct terr_id,region,bsm, md_zip,md_addr1,md_addr2,city,md_state,physician_name, sum(total_scripts) as T_yr_m, productgroup,year_month&lt;BR /&gt;
   from whole_v2&lt;BR /&gt;
   group by terr_id,region, md_zip, bsm, physician_name, year_month, productgroup,md_zip,city,md_state,year_month;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
   ods html file="T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\rpt2b-%sysfunc(DATE(),mmddYYd10.).xls";&lt;BR /&gt;
proc report data=rpt2b nowd NOWINDOWS HEADLINE MISSING;&lt;BR /&gt;
	COLUMN terr_id region bsm md_zip  physician_name md_addr1 md_addr2 city md_state t_yr_m,year_month, productgroup;&lt;BR /&gt;
	define terr_id/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define region/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define bsm/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_zip/group '5 digit zip'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {htmlstyle="mso-number-format:\@" just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE physician_name / group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE year_month / across&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1};&lt;BR /&gt;
	DEFINE productgroup / across &lt;BR /&gt;
	STYLE (header) = [FOREGROUND = black font_size=1];&lt;BR /&gt;
	DEFINE t_yr_m/ format=comma9. ''&lt;BR /&gt;
	STYLE (column) = {font_size=1};&lt;BR /&gt;
	define md_addr1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_addr2/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define city/group 'md_city'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_state/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
   	/****&lt;BR /&gt;
    reason to create compute blocks:&lt;BR /&gt;
	repeat GROUP or ORDER variables for every row.&lt;BR /&gt;
	***/&lt;BR /&gt;
	compute terr_id;&lt;BR /&gt;
	if terr_id ne '' then hold=terr_id;&lt;BR /&gt;
	if terr_id eq '' then terr_id=hold;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	compute bsm;&lt;BR /&gt;
	if bsm ne '' then hold1=bsm;&lt;BR /&gt;
	if bsm eq '' then bsm=hold1;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	compute region;&lt;BR /&gt;
	if region ne '' then hold3=region;&lt;BR /&gt;
	if region eq '' then region=hold3;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	break after terr_id/summarize skip ol style=[font_weight=bold background=grey];&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/***************** End of report2*************/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/********************&lt;BR /&gt;
Report3:Caremark Report by Patient (parta)&lt;BR /&gt;
*********************/&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
 create table pat_seq_id_yr as&lt;BR /&gt;
  select distinct terr_id,region,bsm, md_zip,md_addr1,pat_seq_id1,md_addr2,city,md_state,physician_name, sum(total_scripts) as T_yr, year, productgroup&lt;BR /&gt;
   from whole_v2&lt;BR /&gt;
   group by terr_id,region, md_zip, bsm, physician_name ,pat_seq_id1, year, productgroup,md_zip,city,md_state;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ods html file="T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\rpt3a-%sysfunc(DATE(),mmddYYd10.).xls";&lt;BR /&gt;
proc report data=pat_seq_id_yr nowd NOWINDOWS HEADLINE MISSING;&lt;BR /&gt;
	COLUMN terr_id region bsm md_zip  physician_name md_addr1 md_addr2 city md_state pat_seq_id1 t_yr,year, productgroup ;&lt;BR /&gt;
	define terr_id/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define region/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define bsm/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_zip/group '5 digit zip'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {htmlstyle="mso-number-format:\@" just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE physician_name / group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE pat_seq_id1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {font_size=1.5};&lt;BR /&gt;
	DEFINE year / across&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1};&lt;BR /&gt;
	DEFINE productgroup / across &lt;BR /&gt;
	STYLE (header) = [FOREGROUND = black font_size=1];&lt;BR /&gt;
	DEFINE t_yr / sum format=comma9. ''&lt;BR /&gt;
	STYLE (column) = {font_size=1};&lt;BR /&gt;
	define md_addr1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_addr2/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define city/group 'md_city'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_state/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
   	/****&lt;BR /&gt;
    reason to create compute blocks:&lt;BR /&gt;
	repeat GROUP or ORDER variables for every row.&lt;BR /&gt;
	***/&lt;BR /&gt;
	compute terr_id;&lt;BR /&gt;
	if terr_id ne '' then hold=terr_id;&lt;BR /&gt;
	if terr_id eq '' then terr_id=hold;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	compute bsm;&lt;BR /&gt;
	if bsm ne '' then hold1=bsm;&lt;BR /&gt;
	if bsm eq '' then bsm=hold1;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	compute region;&lt;BR /&gt;
	if region ne '' then hold3=region;&lt;BR /&gt;
	if region eq '' then region=hold3;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	break after terr_id/summarize skip ol style=[font_weight=bold background=grey];&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
/******End report3:Caremark Report by Patient (parta)********************/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/********************&lt;BR /&gt;
Report3:Caremark Report by Patient (partb)&lt;BR /&gt;
*********************/&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
 create table pat_seq_id_yr_m as&lt;BR /&gt;
  select distinct terr_id,region,bsm, md_zip,md_addr1,pat_seq_id1,md_addr2,city,md_state,physician_name, sum(total_scripts) as T_yr_m, year_month, productgroup&lt;BR /&gt;
   from whole_v2&lt;BR /&gt;
   group by terr_id,region, md_zip, bsm, physician_name ,pat_seq_id1, year_month, productgroup,md_zip,city,md_state;;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
ods html file="T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\rpt3b-%sysfunc(DATE(),mmddYYd10.).xls";&lt;BR /&gt;
proc report data=pat_seq_id_yr_m nowd NOWINDOWS HEADLINE MISSING;&lt;BR /&gt;
	COLUMN terr_id region bsm md_zip  physician_name md_addr1 md_addr2 city md_state pat_seq_id1 t_yr_m,year_month, productgroup;&lt;BR /&gt;
	define terr_id/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define region/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define bsm/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_zip/group &lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {htmlstyle="mso-number-format:\@" just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE physician_name / group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	DEFINE pat_seq_id1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {font_size=1.5};&lt;BR /&gt;
	DEFINE year_month / across&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1};&lt;BR /&gt;
	DEFINE productgroup / across &lt;BR /&gt;
	STYLE (header) = [FOREGROUND = black font_size=1];&lt;BR /&gt;
	DEFINE t_yr_m / sum format=comma9. ''&lt;BR /&gt;
    STYLE (column) = {font_size=1};&lt;BR /&gt;
	define md_addr1/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_addr2/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define city/group 'md_city'&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	define md_state/group&lt;BR /&gt;
	STYLE (header) = {just=left  font_size=1}&lt;BR /&gt;
	STYLE (COLUMN) = {just=left  font_size=1.5};&lt;BR /&gt;
	/****&lt;BR /&gt;
    reason to create compute blocks:&lt;BR /&gt;
	repeat GROUP or ORDER variables for every row.&lt;BR /&gt;
	***/&lt;BR /&gt;
	compute terr_id;&lt;BR /&gt;
	if terr_id ne '' then hold=terr_id;&lt;BR /&gt;
	if terr_id eq '' then terr_id=hold;&lt;BR /&gt;
    endcomp; &lt;BR /&gt;
	compute bsm;&lt;BR /&gt;
	if bsm ne '' then hold2=bsm;&lt;BR /&gt;
	if bsm eq '' then bsm=hold2;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	compute region;&lt;BR /&gt;
	if region ne '' then hold3=region;&lt;BR /&gt;
	if region eq '' then region=hold3;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	compute md_zip;&lt;BR /&gt;
	if md_zip ne '' then hold4=md_zip;&lt;BR /&gt;
	if md_zip eq '' then md_zip=hold4;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
	break after terr_id/summarize skip ol style=[font_weight=bold background=grey ];&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/******Endreport3:Caremark Report by Patient (partb)********************/&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %do;&lt;BR /&gt;
%put Errors occurred. Exporting Errors data set to erordatabase; &lt;BR /&gt;
 proc export data=work.errors&lt;BR /&gt;
   dbms=excel2000&lt;BR /&gt;
   outfile='T:\NovoLand\Biopharm Business Analysis SAS Project (2009)\BSM Prescriber Reports\errors.xls';&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
 &lt;BR /&gt;
%check_errors;</description>
      <pubDate>Fri, 08 May 2009 15:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/error-Handling/m-p/29189#M5489</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-05-08T15:28:11Z</dc:date>
    </item>
  </channel>
</rss>

