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

Hi. The resulting dataset stores the 5 character imb_dlvry_zip_5 without leading zeros. So an imb_dlvry_zip_5 of 02367 is stored as 2367. The result is that the following Proc Print also outputs the imb_dlvry_zip_5 value without the leading zero.  How can I prevent it from doing this?  I'd appreciate any help.

 

proc sql;
 create table HighsAndLows as 
 select imb_dlvry_zip_5, rule_nm, rule_order, percent, total
 from myDSs.QueryDataSummary&QTR
 where imb_dlvry_zip_5 <> '164'
   and rule_nm NOT in('TOTAL BIDS VOLUME SAMPLED')
 group by rule_nm
 having total = max(total) or total = min(total)
 order by rule_order, rule_nm, total, imb_dlvry_zip_5;
quit;

proc print label noobs;
label imb_dlvry_zip_5 = 'ZIP5';
run;
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, then this is a well known problem.  It is not SAS however, but Excel which trims off leading zeros of numerical data, that is its default behaviour.  To get around this you need to tell it, via tags, that it should treat the number as character (you will have seen this with the small gree triangle in the cell):

proc report data=<your dataset> nowd;
  columns _all_;
  define imb_dlvry / "Label for variable" style={tagattr='format:text'};
run;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post example data of what you have.  If IMB_DLVRY is indeed character in the table you take the data from then it would be character in the output as well, hence it would retain the "0" at the front.  If however it is numeric, then the default is to not have leading zeros as they are meaningless.  You can use Zx. format if you really need them, but Excel and things will remove them also unless you stipulate text.

buechler66
Barite | Level 11

 

I'v traced the imb_dlvry_zip_5 variable from the original permanent ds to the temporary ds following the Proc SQL and it remains a character value throughout and retains the leading zero.

 

So it now seems as tho it's my output using ODS that may be causing my issue.  Sorry I didn't include this in the original post. Any ideas what may be happening here?

 

/*	Output to XML Excel ready format */
ods tagsets.excelxp file="c:\PTH_&QTR._Highs_and_Lows.xml" 
						style=statistical options(orientation='portrait' gridlines='yes' sheet_name="&QTR" embedded_titles='yes');
title j=left "PTH Highs and Lows for Quarter &QTR";
proc print label noobs;
label imb_dlvry_zip_5 = 'ZIP5';
run;
ods tagsets.excelxp close;

 


Capture.JPG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, then this is a well known problem.  It is not SAS however, but Excel which trims off leading zeros of numerical data, that is its default behaviour.  To get around this you need to tell it, via tags, that it should treat the number as character (you will have seen this with the small gree triangle in the cell):

proc report data=<your dataset> nowd;
  columns _all_;
  define imb_dlvry / "Label for variable" style={tagattr='format:text'};
run;
buechler66
Barite | Level 11

Hmm sounds promising, but I must be doing something wrong still.

 

ods tagsets.excelxp file="c:\PTH_&QTR._Highs_and_Lows.xml" 
style=statistical options(orientation='portrait' gridlines='yes' sheet_name="&QTR" embedded_titles='yes');
title j=left "PTH Highs and Lows for Quarter &QTR";
proc print noobs;
columns _all_;
define imb_dlvry_zip_5 / "ZIP5" style={tagattr='format:text'};
run;
ods tagsets.excelxp close;

 

379 ods tagsets.excelxp file="c:\PTH_&QTR._Highs_and_Lows.xml"
380 style=statistical options(orientation='portrait' gridlines='yes' sheet_name="&QTR"
380! embedded_titles='yes');
NOTE: Writing TAGSETS.EXCELXP Body file: c:\PTH_164_Highs_and_Lows.xml
NOTE: This is the Excel XP tagset (Compatible with SAS 9.1.3 and above, v1.122, 01/04/2011). Add options(doc='help') to the
ods statement for more information.
382 title j=left "PTH Highs and Lows for Quarter &QTR";
384 proc print noobs;
385 columns _all_;
-------
180
386 define imb_dlvry_zip_5 / "ZIP5" style={tagattr='format:text'};
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
388 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 564.67k
OS Memory 21644.00k
Timestamp 11/11/2016 10:29:58 AM

389 ods tagsets.excelxp close;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Look at the difference between your program and mine, particularly the "proc report" versus "proc print" as they have different syntax.  Personally I would use report as its more flexible.

buechler66
Barite | Level 11

Thanks so much for the help. I appreciate your time.

Kurt_Bremser
Super User

To display numeric values with leading zeroes, use the Zw. format. To store such values, you need to put them into a character variable, using the same Zw. format.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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