BookmarkSubscribeRSS Feed
alepage
Barite | Level 11
%let env=p;
LIBNAME library "/dwh_actuariat/sasprocess/prodmens/HYFI&env./format";
OPTIONS FMTSEARCH=(LIBRARY.cerform);


%macro readtxtfile(year,month);
filename prd "/dwh_actuariat/sasprocess/prodmens/HYFIp/output/HyFIPrems&year.&month..txt";

data HyFIPrems&year.&month.;

	INFILE PRD LRECL=150 recfm=v;
			INPUT
                    @  1 CIE                      $CHAR1.
				@  2 PROVINCE_CD              $FPROVHF.
				@  6 BRANCH                   $CHAR2.
				@  8 PRIORCUR                 $CHAR1.
				@  9 POLSCR                   $CHAR1.
				@ 10 MOIS                     $CHAR6.
				@ 16 LOB                      $CHAR8.
				@ 24 TRANS                    $CHAR3.
				@ 27 WP                       15.2
				@ 42 EP                       15.2
				@ 57 EU                       15.2
				@ 72 WU                       15.2
				@ 87 NEWREN                   $CHAR1.
				@ 88 POLCNT                   15.2
				@103 POLEARN                  15.2
				@118 UW_CIE                   $CHAR1.
				@119 DIST_CIE                 $CHAR1.
				@120 OB_IND                   $CHAR5.
				@125 broker_group_ind         $CHAR2.
        			@127 GCNA_BRANCH              $CHAR2.
        			@129 POLICY_CATEGORY          $CHAR1.
        			@130 NETWORK_PROVIDER         $CHAR5.
        			@135 AFFINITY_IND             $CHAR1.
				;
		run;

%mend readtxtfile;
%macro hyfiprem;
%do year=2025 %to 2025;
     %do month=01 %to 08;
     %let months= %sysfunc(putn(&month, z2.));
          %put &year.&months.;

          %readtxtfile(&year,&months);

     %end;
%end;
%mend hyfiprem;
%hyfiprem;

202501
NOTE: Line generated by the invoked macro "READTXTFILE".
80 $FPROVHF. @ 6 BRANCH $CHAR2. @ 8 PRIORCUR $CHAR1. @ 9
_________
485
80 ! POLSCR $CHAR1. @ 10 MOIS $CHAR6. @ 16 LOB $CHAR8.
80 ! @ 24 TRANS

NOTE 485-185: Informat $FPROVHF was not found or could not be loaded.

 

How to solve that issue

 

6 REPLIES 6
Kathryn_SAS
SAS Employee

Is $FPROVHF a format or an informat? Can you send the results of the following:

proc format library=library.cerform fmtlib;
run;
Kathryn_SAS
SAS Employee

What you show is a format; but you reference it on an INPUT statement, so SAS is looking for an Informat with that name.

data_null__
Jade | Level 19

You need an INFORMAT

 

proc format;
   invalue $FPROVHF(upcase just default=2)
      'AB','BC','CD'=_same_
      other='OT'
      ;
   quit;

data test;
   input PROVINCE_CD :$FPROVHF.; 
   cards;
XY
AB
XT
BC
;
   run;
proc print;
   run;

/*   NOTE 485-185: Informat $FPROVHF was not found or could not be loaded.*/

 

Tom
Super User Tom
Super User

Remember that FORMATs convert values into text.

To convert text into values you need an INFORMAT.

 

So define the INFORMAT named $FPROVHF before trying to use it to create the character variable PROVINCE_CD by reading the values starting at column 2 of your text file.

 

Also make sure the default width is not longer than 4 or it might try to "eat" the values of BRANCH from columns 6 and beyond.

 

Are you sure you want to use a custom INFORMAT to read in the values?  Wouldn't it be better to just read in the values using the normal $ informat that would not try to modify them and then attach a FORMAT to the variable so it is displayed the way you want.

 

And what is with the use of the $CHAR informat for the other character variables? That will do two silly things.  

 

For longer fields like NETWORK_PROVIDER $CHAR5. it will preserve any leading spaces.  Which can cause confusion because the value 'BC' will not not match '   BC', even if ODS outputs (like HTML) will make them appear the same.

 

And $CHAR will treat a value consisting of just a single period as a normal period, instead of translating it into spaces as the normal $ informat would.  The reason the $ informat does that is so you can use a period to indicate a missing (empty) value for both the numeric and the character variables.

ballardw
Super User

You can use Proc Format to tell you about the custom formats/informats you have available. 

Example that creates one format and one informat in the Work library and default format catalog. Then 

gets the descriptions with the FMTLIB option. Run the below code and see in the description the the $ABC has the words FORMAT NAME, indicating it is an output format and $PDQ has INFORMAT NAME indicating it is used for reading.

 

You would want to use Library=LIBRARY.cerform in the Proc format statement to examine you custom formats. 

 

/* create a custom format to use later*/

proc format ;
value $abc
'abc'='some formatted result'
;
invalue $pdq
'pdq'='input result value'
;
run;
/* get descriptions of the current custom format/informats */
proc format library=work fmtlib;
run;

 I would quite often have an informat/format pair defined because the INVALUE has different options available such as <some value description> = _error_ to report in the log that the value encountered may not be valid and reports as such in the log, or to create special missing values that a FORMAT could then provide details about when requested. Plus for reading text the INVALUE option UPCASE is very helpful to standardize values so that Abc, ABc, aBc, abC (etc) are all read into the value ABC.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 292 views
  • 0 likes
  • 5 in conversation