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

I came across a data step like this in my program:

data test  ;

   infile '/sasdata/REF.txt'

          lrecl = 256

          delimiter = '    '

          dsd

          missover

          firstobs = 2;

   ;

   attrib MODEL_NM length = $11

      format = $11.

      informat = $11.;          

   input MODEL_NM;  

attrib GRADE_ID length = $3

      format = $3.

      informat = $3.;

input MODEL_NM GRADE_ID

run;

My questions are:

1. Why we need to specify length explicitly, when it is already specified in the format and informat?

2. The delimiter '  '---> if the column model_nm has a value like 'ABC  123' will it read correctly as one column...or as separate columns because of the space?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your first question is backward.  The FORMAT attached to a variable just defines how it should be displayed.  It is only as a side effect that it has an impact on the defined length of the variable. The real problem with this example is the attachment of permanent FORMAT and INFORMAT to simple character variables.  These can cause trouble for later users. If they inadvertently get attached to a longer variable the values will appear as if they have been truncated.

If you tell SAS to use the DSD option then two adjacent delimiters are treated as an indication of a missing value.  So if in you example the line had two spaces between 'ABC' and '123' then GRADE_ID would be assigned a missing value and the '123' would be ignored.

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

Your first question is backward.  The FORMAT attached to a variable just defines how it should be displayed.  It is only as a side effect that it has an impact on the defined length of the variable. The real problem with this example is the attachment of permanent FORMAT and INFORMAT to simple character variables.  These can cause trouble for later users. If they inadvertently get attached to a longer variable the values will appear as if they have been truncated.

If you tell SAS to use the DSD option then two adjacent delimiters are treated as an indication of a missing value.  So if in you example the line had two spaces between 'ABC' and '123' then GRADE_ID would be assigned a missing value and the '123' would be ignored.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1093 views
  • 0 likes
  • 2 in conversation