BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

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.

1 REPLY 1
Cynthia_sas
Diamond | Level 26

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1391 views
  • 0 likes
  • 2 in conversation