Help using Base SAS procedures

Do we need to create informat in data step?

Reply
Regular Contributor
Posts: 222

Do we need to create informat in data step?

Hello everyone,

I know in data step we can set a format to a numeric variable to show it as a different format,such a

data class;

Format     height comma12.5;

set sashelp.class ;

run;

My question is :do we sometime need to use informat in data step? if so what is the purpose?

such as

data class;

Informat height comma12.3;

set sashelp.class ;

run;

:

Thank you!

Mike

Occasional Contributor
Posts: 17

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis
PROC Star
Posts: 7,489

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis

and, using the same documentation that Akilan referred to, take a look at: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000148073.htm

as well as the other ways of using the input statement shown in the list on the left side of that link

Super User
Posts: 11,343

Re: Do we need to create informat in data step?

I use a fair number of custome informats when reading text files prepared by contractors to reduce long text to a documented code value.

For example the following infromat $HIV_ConfirmatorySample is used to read in a text field to codes used prior to the current contractor data extract provides. I often have a complimentary display format that produces shorter text in reports as the humans using the data tend to think of hte values such as "Declined" or "Referred".

 

invalue $ConfirmatorySample (just max=4 upcase)

"YES" = "01"

"DECLINED CONFIRMATORY TEST" = "2.01"

"REFERRED TO ANOTHER AGENCY" = "2.02"

"DID NOT RETURN/COULD NOT LOCATE" = "2.03"

"OTHER REASON" = "88"

;

The shorted display formats make the data easier to read in table viewers instead of the original long text as well.

While not as important as when memory and disk space was more expensive storing 2 ro 3 characters instead of as many as 80 can still improve performance sometimes.

Regular Contributor
Posts: 222

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis

Thank you all!

I am still very confuse,so please at first tell me what is the purpose of the following "informat"?

Thanks!

data class;

Informat height comma12.3;

set sashelp.class ;

run;

PROC Star
Posts: 7,489

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis

Mike,

Not a lot, other than it will move height to be the left-most variable since the statement comes before the set statement.

While one wouldn't typically add records to a file by setting the existing file and then using cards and an input statement, if you did, the values for height would now have to match the newly assigned informat.

Super User
Super User
Posts: 7,074

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis

It really should have little effect. To me it looks like someone wanted to attach a format and accidentally typed INFORMAT instead of FORMAT.   As Art mentions the main effect will be to cause SAS to place HEIGHT as the first variable and set the name as a 'height' instead of 'Height'. It is very hard to tell what the purpose is without a comment from the original coder.  Possible purposes:

- The changes that it causes.

- They plan to edit the file interactively with FSEDIT and want to be able to type or paste in values with commas.

- They want to set the attached informat metadata to help document the variable.

Super User
Posts: 5,516

Re: Do we need to create informat in data step?

Posted in reply to Mike_Davis

Very rare these days, but it could happen.  If you wanted to display the data interactively, and let the user edit the data, the informat might be useful.  For example, there might be a subsequent DATA step that uses WINDOW and DISPLAY statements, and lets the user edit the data values.

Also be very wary of using an informat with positions after the decimal point.  They change the variable's value, if the incoming text does not contain a decimal point.  But that's another story for another day.

Ask a Question
Discussion stats
  • 7 replies
  • 269 views
  • 0 likes
  • 6 in conversation