BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6

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

7 REPLIES 7
art297
Opal | Level 21

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

ballardw
Super User

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.

Mike_Davis
Fluorite | Level 6

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;

art297
Opal | Level 21

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.

Tom
Super User Tom
Super User

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.

Astounding
PROC Star

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.

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!

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.

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
  • 983 views
  • 0 likes
  • 6 in conversation