Help using Base SAS procedures

Format zip codes in ods tagset

Reply
Contributor
Posts: 59

Format zip codes in ods tagset

DEFINE  BO_ZIP_CD    /  Display style(column)={tagattr="format:@" cellwidth=80pt just=center"BILLING ZIP";

The above code is being used in a program using ods tagset.  The output is an xml file.  If the zip code is something like 30011 then I am fine.  If the zip code is 300112222 I want to format the zipcode as 30111-2222.

If it is easier to address this in the dataset then let me know.  I believe there is a way to address in the ods output though.

SAS Super FREQ
Posts: 8,868

Re: Format zip codes in ods tagset

Posted in reply to omega1983

Hi:

  I believe you will need to use CALL DEFINE in a COMPUTE block to specify a different format when you have a zip+4 versus just a zip code (based on the length of the data value).

cynthia


data testzip;
length name $12 zip_cd $9;
infile datalines;
input name $  zip_cd $;
return;
datalines;
alan 300112222
barb 202113333
carl 20022
dave 00221
edna 003334444
fran 777
;
run;

  
ods tagsets.excelxp file='c:\temp\zipcode.xml' style=sasweb;
 
proc report data=testzip nowd;
   column name zip_cd;
   define name / order;
   define zip_cd / display "Zip Code";
   compute zip_cd;
      lgzp = length(zip_cd);
      if lgzp = 9 then do;
        call define(_col_,'style',
                    'style={tagattr="format:00000\-0000" cellwidth=80pt just=center}');
      end;
      else if lgzp le 5 then do;
        call define(_col_,'style',
                    'style={tagattr="format:00000" cellwidth=80pt just=center}');
      end;
   endcomp;
  
run;
   
ods tagsets.excelxp close;

Ask a Question
Discussion stats
  • 1 reply
  • 227 views
  • 0 likes
  • 2 in conversation