Help using Base SAS procedures

Proc Format problem - resolving values with PUT in UNIX

Reply
New Contributor
Posts: 2

Proc Format problem - resolving values with PUT in UNIX

Hello, thank you in adavance for your time and insight into solving my problem.

I am attempting to use a SAS FORMAT named $SICLONG. which I created using OSHA's SIC classifications. I was suscessful in creating it using the proc format cntlin option and it is stored in my home directory in a UNIX environment. I can also acess it with proc catalog and sucesssfully print it ubsing the following...

proc format library = MYFMT.formats fmtlib; SELECT $SICLONG; run;



However, when I attempt to call $SICLONG. in my program it does not error out, but all the values all resolve to "not found" which is the last format class. Interestingly, I also create a local proc format (named $sic.) which does resolve satisfactorily. The program is long, so I'm attching the important elemts below.




/**************************** PROGRAM ****************************/
libname MYFMT '/home/oselw';
OPTIONS FMTSEARCH=(MYFMT) obs=1000;

proc format;
value $sic
'01','02','07','08','09'='A: Agriculture, Forestry & Fishing'
'10','12','13','14'='B: Mining'
'15','16','17'='C: Construction '
/*... more classifications here*/
;
run;

data output_data_set;
set input_data_set;
/*unrelated stuff*/
mt_sic=substr(mt_industry,1,2);
mt_sic2=substr(mt_industry,1,4);
Master_sic=put(mt_sic, $sic.); /**** THIS WORKS*/
Master_sic2=put(mt_sic2, $SICLONG.); /**** THIS DOESNT WORK*/
run;




/**************************** OUTPUT ****************************/
The SAS System 12

Contents of Catalog MYFMT.FORMATS

# Name Type Create Date Modified Date
---------------------------------------------------------------------
1 INCOME FORMAT 11MAR2009:12:09:35 11MAR2009:12:09:35
2 INCOME FORMATC 11MAR2009:12:31:51 11MAR2009:12:31:51
3 SICLONG FORMATC 06MAR2009:09:55:43 06MAR2009:09:55:43
4 SIC_LON FORMATC 05MAR2009:14:15:18 05MAR2009:14:15:18

Contents of Catalog MYFMT.FORMATS

Last Last
Page Block Num of Block Block
# Description Size Size Blocks Bytes Size Pages
----------------------------------------------------------------------
1 4096 4096 519 1684 2040 519
2 4096 4096 393 1003 1020 393
3 4096 4096 9 1098 1275 9
4 4096 4096 9 1104 1275 9

The SAS System 13

----------------------------------------------------------------------------
| FORMAT NAME: $SICLONG LENGTH: 60 NUMBER OF VALUES: 445 |
| MIN LENGTH: 1 MAX LENGTH: 60 DEFAULT LENGTH 60 FUZZ: 0 |
|--------------------------------------------------------------------------|
|START |END |LABEL (VER. 8.2 06MAR2009:09:55:43)|
|----------------+----------------+----------------------------------------|
|100 |100 |AGRICULTURAL PRODUCTION-CROPS |
|200 |200 |AGRICULTURAL PROD-LIVESTOCK & ANIMAL SPE|
|700 |700 |AGRICULTURAL SERVICES |
|800 |800 |FORESTRY |
|900 |900 |FISHING, HUNTING AND TRAPPING |
|1000 |1000 |METAL MINING | Thanks Scott! I don't have the comments in my program, but I appreciate the clarification for everyone who's looking!


Message was edited by: oliver_selwyn
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Format problem - resolving values with PUT in UNIX

Posted in reply to oliver_selwyn
One obvious item is your SAS comment syntax. If you start the comment with an asterisk character, the comment will not be terminated until the next semi-colon -- you have an asterisk and slash which is treated as part of the comment.

So, I would say that your code is not executing, which would be the cause of your symptom.

Consider adding the following self-diagnosis statement in your program for debugging purposes:

putlog '>diag00>' / _all_;

Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 2

Re: Proc Format problem - resolving values with PUT in UNIX

Posted in reply to oliver_selwyn
Cool tip, Scott - I haven't seen putlog before. Bold elements are where I assume the prooblem is occuring. Here's what it gives me...

>diag00>
mt_sic=73 mt_sic2=7389 bin=13 enhanced_business_name=BO ENTERPRISES INC exec_primary_sic=
abi_primary_sic= db_primary_sic=73890000 dmi_csad_primary_sic=7389 nbd_sic_1_code=73890000
eqf_sic=508400 mald_EXT1PRIMARYSIC=73890000 nbd_primary_sic=73890000 I=8 mt_industry=7389
Master_sic=I: Services Master_sic2=not found _ERROR_=0 _N_=2
Trusted Advisor
Posts: 2,116

Re: Proc Format problem - resolving values with PUT in UNIX

Posted in reply to oliver_selwyn
The problem is probably with your crtlin dataset. Looking at your output of $siclong, you may have trailing blanks in the ctrlin data and that may be causing the non-matches (It's a bit hard to see, there appear to be trailing blanks after all the codes, but not after all the text.)
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Format problem - resolving values with PUT in UNIX

You really need to validate the content of your format - that's something only you can do, given the large size and the limits of this forum environment.

One test to validate your SAS format is to unload it with PROC FORMAT and CNTLOUT= to a SAS file, for close inspection, as compared to your data file.

After doing a CONTENTS against the CNTLOUT= file to get familiar with it, review the SAS-generated variables START, LABEL, and HLO data values, to start, if you are working with explicit values in the format (rather than value ranges -- a bit more complicated).

Then sort your two files and do a MERGE in a DATA step. If you cannot get the MERGE to work, then you have some type of garbage in the format (determined from a PROC PRINT of START variable with a hex-type character display format.


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 96 views
  • 0 likes
  • 3 in conversation